JAVA 复写
发布时间:2020-12-15 07:16:47 所属栏目:Java 来源:网络整理
导读:子类对 introduce 进行复写 public class Person { String name; int age; Person(String name, age) { this .name = name; this .age = age; System.out.println( "Person 二参构造" ); } void introduce() { System.out.println( "我的名字是" + name + ",
子类对introduce进行复写 public class Person { String name; int age; Person(String name, age) { this.name = name; this.age = age; System.out.println("Person 二参构造"); } void introduce() { System.out.println("我的名字是" + name + ",我的年龄是" + age); } } class Student extends Person {
String address;
public Student(String name, age,String address) {
super(name,age);
this.address = address;
}
address);
}
}
Test {
public Test() {
// TODO Auto-generated constructor stub
}
static main(String[] args) {
TODO Auto-generated method stub
Student student = new Student("furong",12,"BeiJing");
student.introduce();
}
}
运行结果 Person 二参构造
我的名字是furong,我的年龄是12,我的地址是BeiJing
子类改进 introduce() {
.introduce();
System.out.println("我的地址是" + address);
}
} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |