1.在子类中访问父类得人成员
在学生子类Student中访问父类Person的成员
package practice;
class Person2{
protected String name;
protected int age;
public Person2() {}
public Person2 (String name,int age) {
this.name = name;
this.age = age;
}
protected void show() {
System.out.println(“姓名”+name+“年龄”+age);
}
}
class Student2 extends Person2{
private String department;
int age = 20;
public Student2(String xm,String dep) {
name = xm;
department = dep;
super.age = 25;
System.out.println(“子类student中的成员变量age=”+age);
super.show();
System.out.println(“系别:”+department);
}
}
public class eee {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student2 stu = new Student2("李小四","信息系");