//方法类
class Tip
{
private String title="我是新手,请大家指教";
private String content="我刚开始学JAVA,请大家指教";
private String publishTime="2014-12-22 0";
private int uid=1;
private String data="本帖有效期从开始计算6个月后过期";
/*
* 无参数构造方法
*/
public Tip()
{
title="我是新手,请大家指教";
content="我刚开始学JAVA,请大家指教";
publishTime="2014-12-22 0";
data="2015-6-22";
System.out.println("帖子类的无参构造方法");
}
/*
* 帖子类的有参构造方法
*/
public Tip(String title,String content,String publishTime,String data)
{
title="我是新手,请大家指教";
content="我刚开始学JAVA,请大家指教";
publishTime="2014-12-22 0";
data="2015-6-22";
System.out.println("帖子类的有参构造方法");
}
public void getInfo()
{
System.out.println("====帖子信息====");
System.out.println("帖子标题:"+title);
System.out.println("帖子内容:"+content);
System.out.println("发表时间:"+publishTime);
System.out.println("有效期:"+data);
}
}
//测试类
class EntityTest3
{
public static void main(String[] args)
{
Tip tip = new Tip();
tip.getInfo();
System.out.println();
Tip tip3 = new Tip("一个经典的Java程序","HelloAccp","2014-12-22","2015-6-22");
tip3.getInfo();
}
}
|
|