一个关于Java构造方法的小问题(在线求解)
题目:使用主题类的午餐构造方法创建主体对象topic1和topic2,使用主题类的setter方法为topic1和topic2的属性设值。使用topic2的getTopi...
题目:
使用主题类的午餐构造方法创建主体对象topic1和topic2,使用主题类的setter方法为topic1和topic2的属性设值。使用topic2的getTopicInfo()方法输出topic2的信息,使用topic2的getTopicInfo(Topic topic)方法输出topic1的信息。(在线求高手解答!!!) 展开
使用主题类的午餐构造方法创建主体对象topic1和topic2,使用主题类的setter方法为topic1和topic2的属性设值。使用topic2的getTopicInfo()方法输出topic2的信息,使用topic2的getTopicInfo(Topic topic)方法输出topic1的信息。(在线求高手解答!!!) 展开
1个回答
展开全部
public class Topic {
String topicInfo;
String getTopicInfo() {
return this.topicInfo;
}
String getTopicInfo(Topic topic) {
return topic.topicInfo;
}
void setTopicInfo(String info) {
this.topicInfo = info;
}
public static void main(String[] args) {
Topic topic1 = new Topic();
Topic topic2 = new Topic();
topic1.setTopicInfo("This is topic1");
topic2.setTopicInfo("This is topic2");
System.out.println(topic1.getTopicInfo());
System.out.println("~~~~~~~~~~~~~~~~~~~~~");
System.out.println(topic1.getTopicInfo(topic2));
}
}
String topicInfo;
String getTopicInfo() {
return this.topicInfo;
}
String getTopicInfo(Topic topic) {
return topic.topicInfo;
}
void setTopicInfo(String info) {
this.topicInfo = info;
}
public static void main(String[] args) {
Topic topic1 = new Topic();
Topic topic2 = new Topic();
topic1.setTopicInfo("This is topic1");
topic2.setTopicInfo("This is topic2");
System.out.println(topic1.getTopicInfo());
System.out.println("~~~~~~~~~~~~~~~~~~~~~");
System.out.println(topic1.getTopicInfo(topic2));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |