I learned because I didn't understand java abstract.
-Cannot create an instance directly ยท Force subclasses to override -It is necessary to write a constructor in a subclass
sample.java
abstract class Abst_sample {
abstract void abstractMethod(int num, String str);
void nonAbstractMethod() {
System.out.println("Output from non-abstract method");
}
}
public class sample extends Abst_sample {
public static void main(String[] args) {
sample aaa = new sample();
//After inheriting, it creates its own instance and calls abstractMethod.
aaa.abstractMethod(3, "Test");
}
@Override
public void abstractMethod(int num, String str) {
System.out.println("Argument int num= " + num + " /Argument String str= "+ str);
}
}
I think it's an image that gives an instruction to "use such a method".
When developing with a large number of people, such a function will be needed.
There is no loss to remember.
https://www.sejuku.net/blog/22689
Recommended Posts