定义一个人类(Person),声明在包app.father,它包含
发布网友
发布时间:2022-05-27 00:22
我来回答
共1个回答
热心网友
时间:2024-12-05 09:58
//person类
package app.father;
public class Person {
private String name;
private char sex;
public Person(String name, char sex) {
super();
this.name = name;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public void print() {
// 控制台输出此类姓名,性别详细信息
System.out.println("Person [name=" + name + ", sex=" + sex + "]");
}
}
//student类
package app.son;
import app.father.Person;
public class Student extends Person {
private int id;
public Student(String name, char sex,int id) {
super(name, sex);
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void print(){
//控制台输出此类详细信息
System.out.println("Student [name=" + getName() + ", sex=" + getSex() + ",id=" + id + "]");
}
}
main方法
package app.test;
import app.father.Person;
import app.son.Student;
public class test {
public static void main(String[] args) {
Person stu=new Student("person1",'男',1);
stu.print();
}
}
追问无法运行,没有接口--接口不对啊