Came across interesting inheritance / overriding issue (taken from here ).
When both Base and Derived classes are abstract, and
I don't understand why Eclipse IDE calls it in Derived
Snippet 1:
public abstract class Girl {
abstract String getDescription();
}
abstract class GirlDecorator extends Girl {
abstract String getDescription(); // implements Girl.getDescription() - says Eclipse IDE
}
Snippet 2:
public abstract class Girl {
String description = "no particular";
String getDescription() {
return description;
}
}
abstract class GirlDecorator extends Girl {
abstract String getDescription(); // overrides Girl.getDescription() - says Eclipse IDE
}
In Java there are two types of methods (non-static)
Virtual - Normal method, must be implemented in the base class but can be overridden by inheritance.
Abstract - Method that is not implemented in the base class but in the derived class.
So that wraps it, virtual methods are not implemented in the derived class, they are implemented in the base class and can be overridden by the derived class. Abstract methods are not implemented in the base class, they are implemented in the derived class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.