public class Demo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Son son = new Son();
son.show();// father age50
son.show2();// 方法的age20 成员变量age30 父类的age50
}
}
class Father {
int age = 50;
int h = 175;
public void show() {
System.out.println(age);
}
}
class Son extends Father {
int age = 30;
public void show2() {
int age = 20;
System.out.println(age);// 20
System.out.println(this.age);// 30
System.out.println(super.age);// 50
}
}
super的使用,我觉得还是父类的都加上get set吧那样子类的构造方法直接super带参数的就行了
public class Demo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Son son = new Son();
son.show();// father age50
son.show2();// 方法的age20 成员变量age30 父类的age50
bigStudent yyzBigStudent = new bigStudent(20, "yinyiz");
System.out.println(yyzBigStudent.age);
System.out.println(yyzBigStudent.getName());
}
}
class Father {
int age = 50;
int h = 175;
public void show() {
System.out.println(age);
}
}
class Son extends Father {
int age = 30;
public void show2() {
int age = 20;
System.out.println(age);// 20
System.out.println(this.age);// 30
System.out.println(super.age);// 50
}
}
class Students {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
int age;
Students() {
}
Students(String name, int age) {
this.age = age;
this.name = name;
}
}
class bigStudent extends Students {
int age;
public bigStudent() {
// TODO 自动生成的构造函数存根
}
bigStudent(int age, String name) {
super(name, age);
this.age = age;
}
}
仅用于记录
下面上第二段的输出结果
50 20 30 50 20 yinyiz



