+2 votes
in Dot Net by

What's the difference between an interface and abstract class?

2 Answers

0 votes
by

nterfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.

0 votes
by

Java provides and supports the creation both of abstract classes and interfaces. Both implementations share some common characteristics, but they differ in the following features:

  1. All methods in an interface are implicitly abstract. On the other hand, an abstract class may contain both abstract and non-abstract methods.
  2. A class may implement a number of Interfaces, but can extend only one abstract class.
  3. In order for a class to implement an interface, it must implement all its declared methods. However, a class may not implement all declared methods of an abstract class. Though, in this case, the sub-class must also be declared as abstract.
  4. Abstract classes can implement interfaces without even providing the implementation of interface methods.
  5. Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.
  6. Members of a Java interface are public by default. A member of an abstract class can either be private, protected or public.
  7. An interface is absolutely abstract and cannot be instantiated. An abstract class also cannot be instantiated, but can be invoked if it contains a main method.

Related questions

+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
...