定义一个Person类和它的子类Employee,Person类有姓名、地址、电话号码和电子邮箱,然后定义一个方法showMessageO用于输出人的信息。Employee类有办公室、工资和受聘日期成员变量,定义一个方法showMessage0用于输出雇员的信息。将Employee定义为 public类,在其main(方法中分别为基于父类和子类创建两个对象,并分别为父类和子类的成员变量赋值,然后分别调用父类和子类的showMessage0方法来输出信息。
1个回答
关注
展开全部
下面是一个符合要求的Person和Employee类实现:public class Person { private String name; private String address; private String phoneNumber; private String email; public Person(String name, String address, String phoneNumber, String email) { this.name = name; this.address = address; this.phoneNumber = phoneNumber; this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public void showMessage() {
咨询记录 · 回答于2023-06-08
定义一个Person类和它的子类Employee,Person类有姓名、地址、电话号码和电子邮箱,然后定义一个方法showMessageO用于输出人的信息。Employee类有办公室、工资和受聘日期成员变量,定义一个方法showMessage0用于输出雇员的信息。将Employee定义为 public类,在其main(方法中分别为基于父类和子类创建两个对象,并分别为父类和子类的成员变量赋值,然后分别调用父类和子类的showMessage0方法来输出信息。
下面是一个符合要求的Person和Employee类实现:public class Person { private String name; private String address; private String phoneNumber; private String email; public Person(String name, String address, String phoneNumber, String email) { this.name = name; this.address = address; this.phoneNumber = phoneNumber; this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public void showMessage() {
代码部分因为字数限制为您截图