java

总结所有的变量怎么访问,总结所有的方法怎么访问!!!

public class Test07 {
	public static void main(String[] args) {
		Date t =new Date(2008,8,8);
		//new 关键字 表示创建一个对象 实例话对象 表示申请空间
		System.out.println(t.getYear()+":"+t.getMonth()+":"+t.getDay());//引用.成员方法
		Date.seeMoon();	//类.静态方法		
	}

}
class Date {
	//私有 实例变量year 年
	private int year;
	//私有 实例变量month 月
	private int month;
	//私有 实例变量day  日
	private int day;
	static String MOON="月亮";// 静态变量
	//get方法获取  外部程序只能通过set方法修改, 是实例方法 
	public int getYear() {
		return year;
	}
	public void setYear(int year) { //括号里是局部变量
		this.year = year;
	}
	public int getMonth() {
		return month; //也可以写成 return this.month; 就近原则
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getDay() {
		return day;
	}
	public void setDay(int day) {
		this.day = day;
	}
	//无参构造
	public Date() {
//	   this(this year,this.month,thisday);
	}
	//有参构造
	public Date(int year,int month,int day) {
		this();	//调用无参构造
		this.setYear(year);
		this.setMonth(month);
		this.setDay(day);

	}
	//静态方法
	public static void seeMoon() {
		System.out.println(MOON+"有嫦娥");//date.MOON
		//this.MOON; 错误 不能使用this static 不能使用this
	}
	
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值