问 一个 JAVA 编程问题 ?
- 提问者网友:喧嚣尘世
- 2021-05-09 06:41
接着,定义一个继承自Document类的Email类,它包含用于表示email消息的sender、recipient和title成员变量。给出合适的取值和赋值方法。重新定义toString方法,以便把所有的文本字段连接在一起。
再定义一个继承自Document类的File类,它应该包含一个pathname成员变量。
在main方法中创建几个Email和File类型的对象,进行测试。
- 五星知识达人网友:迷人又混蛋
- 2021-05-09 07:02
public class Document {
private String text;
//用于获取text
public String getText() {
return text;
}
//用于设置text
public void setText(String text) {
this.text = text;
}
public String toString(){
return text;
}
}
public class Email extends Document {
private String sender;
private String recipient;
private String title;
public Email() {
super();
}
public Email(String sender, String recipient, String title) {
super();
this.sender = sender;
this.recipient = recipient;
this.title = title;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String toString(){
String str = sender+"发送标题为"+title+"的Email给"+recipient;
return str;
}
}
public class File extends Document {
private String pathname;
public String getPathname() {
return pathname;
}
public void setPathname(String pathname) {
this.pathname = pathname;
}
}
public class Test {
public static void main(String[] args) {
Document email = new Email("枫叶","雨雪","你好");
Document file = new File();
String str = email.toString();
System.out.println(str);
file.setText("同学好!");
System.out.println(file.getText());
}
}
- 1楼网友:神也偏爱
- 2021-05-09 09:32
- 2楼网友:我住北渡口
- 2021-05-09 09:09
- 3楼网友:不如潦草
- 2021-05-09 08:41
能不能说的具体点.