public class Duixiang{
String ename;
int eid;
int eage;
void print(){
System.out.println("姓名: "+ename+"ID号: "+eid+"年龄: "+eage);
}
}
class Example1 extends Duixiang{
String eaddre;
void print1(){
System.out.println("住址: "+eaddre);
}
}
class text{
public static void mian(String args[]){
Duixiang a1=new Example1();
Example1 a2=new Example1();
a1.ename="王二";
a1.eid=21024;
a1.eage=55;
System.out.println("这是一个父类的引用指向子类的对象");
a1.print();
System.out.println("这是子类特有的属性");
a2.eaddre="龙华大道";
a2.print1();
}
} |
|