0
what is the difference between abstract class and interface class?
what is use of those classes?
6 Antworten
+ 5
mon
You can implement other properties by overriding but you dont have to.
Abstract propeties are must or an error will occur
+ 2
Abstract class can only be inherited by other classes. You can not create an instances of it. Abstract class can also contain abstract propeties which the child class must implement when inheriting the class.
Interface is a class which other classes can implement. It describes the structure of the implementing classes. It contains properties that the implementing class must provide
+ 2
You can review this article for a more detailed comparison:
https://www.javatpoint.com/difference-between-abstract-class-and-interface
One important element of OOP concepts, that supports code reuse, is "dynamic polymorphism". In Java this is achieved by inheritance. When two different objects share some common features, it can make sense for them to have a common ancestor in the class hierarchy. So the common features only need to be implemented in one location. It is true for both abstract classes and for interfaces, that they can have method implementations too (in case of interface, this is called default method). Only abstract classes can have internal fields though. interfaces can only have constants (declared as public static final).
Another important difference is that a class can extend only a single parent class (whether it is a normal or abstract class) but it can implement multiple interfaces. Typically we would define an interface to express a certain behavior, which is applicable for a class. Examples are Serializable, Comparable, or Runnable interfaces. Other times we express a contract that the subclasses must follow, in terms of functionality, for example the classes ArrayList and LinkedList both implement the List interface.
+ 1
Toni_Isotalo
Is we must implement only abstract properties in abstract class and other properties we don't??
- 1
abstract class contains an abstract keyword on the declaration.
Interface is a sketch that is used to implement a class.