package Test;
public class ExtendsTwo {
public static void main(String[] args) {
Son s=new Son();
s.print();
}
}
class Father{
int num1=10;
int num2=20;
}
class Son extends Father{
int num2=30;
public void print() {
System.out.println(this.num1);//10 因为子类继承了父类的东西,所以可以用this调用,若子类有,则调用子类的,否则调用父类的
System.out.println(num2);//30 优先调用最近的,其实是相当于this.num2,只是省略了this
System.out.println(super.num2);//20
}
}