What is the difference between an abstract class and an interface?

Possible duplicate:
Interface versus abstract class (generic OO)

Can I create an instance of the Abstract class? If so, why am I not going to abstract all of my unsealed classes?

If I can’t create it, then what is the difference from the interface? Can an abstract class have a β€œbase” class? Is there a difference in the difference between an interface and an abstract class?

+3
source share
6 answers

You cannot instantiate an abstract class.

, , , , . .

+7

. .

, .

.

+4

. / , . , , () , .

abstract class A 
{
    public int Foo() { return 1; } // implementation defined
}

class B : A 
{
}

interface C
{
    int Foo() {return 1;} // not legal, cannot provide implementation in interface
}

// ... somewhere else in code

A a = new A(); // not legal
A a = new B(); // legal
+1

:

  • - .

  • , - .

:

  • - , , .. .

  • - .

  • , .

+1

: . , .

0

, , .

, , , .. .

0

Source: https://habr.com/ru/post/1764544/


All Articles