代码如下
父类
package com.t70.editity;
public class Tip {
public Tip(){}
public Tip(String title,String content,String publishTime){
this.title=title;
this.content=content;
this.publishTime=publishTime;
}
//帖子标题
private String title;
//帖子内容
private String content;
//帖子发表时间
private String publishTime;
//用户主键
private int uid=1;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPublishTime() {
return publishTime;
}
public void setPublishTime(String publishTime) {
this.publishTime = publishTime;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public void getInfo(Tip tip){ //+"\n用户Id:"+this.uid
System.out.println("====帖子信息===="+"\n标题:"+tip.title+"\n内容:"+tip.content+"\n发表时间:"+tip.publishTime+"\n");
}
}
主贴子类
package com.t70.editity;
public class Topic extends Tip {
public Topic() {
// TODO Auto-generated constructor stub
}
public Topic(String title, String content, String publishTime) {
super(title, content, publishTime);
// TODO Auto-generated constructor stub
}
public Topic(String title, String content, String publishTime, int topicId,int boardId) {
super(title, content, publishTime);
this.topicId=topicId;
this.boardId=boardId;
}
private int topicId;
private int boardId;
public int getTopic() {
return topicId;
}
public void setTopic(int topicId) {
this.topicId = topicId;
}
public int getBoardId() {
return boardId;
}
public void setBoardId(int boardId) {
this.boardId = boardId;
}
public void getInfo(Tip tip){
System.out.println("====主贴信息===="+"\n主贴标题:"+this.getTitle()+"\n主贴内容:"+tip.getContent()+"\n发表时间:"+tip.getPublishTime()+"\n");
}
}
回帖子类
package com.t70.editity;
public class Reply extends Tip {
public Reply() {
// TODO Auto-generated constructor stub
}
public Reply(String title, String content, String publishTime) {
super(title, content, publishTime);
// TODO Auto-generated constructor stub
}
public Reply(String title, String content, String publishTime, int uid,int replyId,int topicId) {
super(title, content, publishTime);
this.replyId=replyId;
this.topicId=topicId;
}
private int replyId; //回帖id
private int topicId; //主贴id
public int getReplyId() {
return replyId;
}
public void setReplyId(int replyId) {
this.replyId = replyId;
}
public int getTopicId() {
return topicId;
}
public void setTopicId(int topicId) {
this.topicId = topicId;
}
public void getInfo(Tip tip){
System.out.println("====回帖信息===="+"\n回帖标题:"+tip.getTitle()+"\n回帖内容:"+tip.getContent()+"\n发表时间:"+tip.getPublishTime()+"\n");
}
}
测试类
package com.t70.test;
//import java.util.*;
import com.t70.editity.*;
public class TipTest {
public static void main(String[] args) {
// TODO Auto-generated mexthod stub
//Date date=new Date();
//long time=date.getTime();
//System.out.println(time);
Topic topic=new Topic("C#.....","C#是微软开发的...","2009-11-11 20:50");
Reply relpy=new Reply("废话..","Re:谁不知道啊!!","2009-11-11 21:00");
Tip tip=new Tip();
tip.getInfo(topic);
tip.getInfo(relpy);
}
}
输出结果不对。全是按父类方法输出的。。。 麻烦高手帮我看看是哪里的问题。
不是应该调用父类方法的吗?