I'm studying Java Silver, so I'll upload it as my memorandum. Since it is a rough memo, details are not described.
An abstract method is a method that defines only the method that has no implementation (method name, argument type, number of arguments) and the return type.
Notes
(1) Since it cannot be instantiated directly, instantiate a subclass.
(2) For the above reason, when calling the superclass constructor, it is necessary to describe the constructor in a subclass and use super (); to call the superclass constructor.
③ Override all abstract methods.
(4) The description is as follows, and {} is not described in the abstract method.
abstract class class name {
abstract Return type name Method name (argument);
}
⑤ Inherit and override with extends.
public abstract class _abstract {
public void test(int num) {
System.out.println(1);
method(num);
System.out.println(3);
}
public abstract void method(int num);
}
public class _subabstract extends _abstract{
public static void main(String[] str) {
_subabstract sub = new _subabstract();
sub.test(2);
}
public void method(int num) {
System.out.println(num);
}
}
Override: Define a method with the same method name, number of arguments, and order. Overload: To define a method with the same method name but different number and order of arguments.
Recommended Posts