JAVA编程题,急求呀。。。高手帮下忙
编程完成下面功能:1,定义一个person类成员变量:name,age成员方法:showInfo(),用来显示person对象的内容至少两个构造方法(有参,无参)用于给n...
编程完成下面功能:
1,定义一个person类
成员变量:name,age
成员方法:showInfo(),用来显示person对象的内容
至少两个构造方法(有参,无参)用于给name和age初始化
2,再定义一个Student类,继承Person类
成员变量id,department
成员方法:showInfo(),该方法覆盖Person类中的showInfo()方法
至少两个构造方法(带参,无参),用于给id,department,name,age初始化
3,定义一个测试类TestStudent,分别生成Person对象和Student对象,显示结果。 展开
1,定义一个person类
成员变量:name,age
成员方法:showInfo(),用来显示person对象的内容
至少两个构造方法(有参,无参)用于给name和age初始化
2,再定义一个Student类,继承Person类
成员变量id,department
成员方法:showInfo(),该方法覆盖Person类中的showInfo()方法
至少两个构造方法(带参,无参),用于给id,department,name,age初始化
3,定义一个测试类TestStudent,分别生成Person对象和Student对象,显示结果。 展开
2个回答
展开全部
public class Person {
public String name;
public int age;
public void showInfo(){
System.out.println(name+","+age);
}
public Person(){}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public class Student extends Person{
public int id;
public String department;
public void showInfo() {
System.out.println(id+","+department+","+name+","+age);
}
public Student() {
}
public Student(int id, String department,String name,int age) {
this.id = id;
this.department = department;
super.name=name;
super.age=age;
}
public static void main(String[] args) {
Person p=new Person("张三",22);
Student s=new Student(1,"销售部","李四",23);
p.showInfo();
s.showInfo();
}
}
public String name;
public int age;
public void showInfo(){
System.out.println(name+","+age);
}
public Person(){}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public class Student extends Person{
public int id;
public String department;
public void showInfo() {
System.out.println(id+","+department+","+name+","+age);
}
public Student() {
}
public Student(int id, String department,String name,int age) {
this.id = id;
this.department = department;
super.name=name;
super.age=age;
}
public static void main(String[] args) {
Person p=new Person("张三",22);
Student s=new Student(1,"销售部","李四",23);
p.showInfo();
s.showInfo();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询