Define a new class based on the existing class. (Original class = superclass, newly defined class = subclass At this time, the methods and fields of the superclass are inherited.
Inheritance
class SubClass extends SuperClass {
...
}
Subclasses can be overridden to override the superclass method processing
override
class SubClass extends SupreClass {
@Override methodA() {
super.methodA(); //Execute processing of existing method
...
}
}
The following conditions must be met in order to override. -The method name and arguments are the same. -The return value must be the same as the original method or a subclass -The access modifier is the same as or wider than the original method. -The method must not have the final modifier.
A class that contains methods that do not define what to do.
Abstract class
abstract class AbsClass {
public abstract void methodA();
}
A class that defines the methods that need to be implemented.
Interface
public interface InterfaceSampl(){
public abstract void methodA();
default void methodB(){
...
}
}
Recommended Posts