I'm studying Java Silver, so I'll upload it as my memorandum. Since it is a rough memo, details are not described.
By inheriting the class, it is possible to inherit the parts that are common to the previously created functions. Add "extends" after the class name of the subclass to describe the class name of the inheritance source (superclass).
1: Display as name.
public class _extends {
protected String name;
protected int num;
protected void method(){
System.out.println(num + ":" + name);
}
}
public class _subextends extends _extends{
public void method2(String name,int num) {
super.name = name;
super.num = num;
method();
}
}
public class Test {
public static void main(String[] str){
_subextends e = new _subextends();
e.method2 ("name", 1); } }
Recommended Posts