亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

拿去參考吧

public?class?Shallow_2_1?{

????private?int?year;
????private?int?month;
????private?int?day;

????//?主方法
????public?static?void?main(String[]?args)?{
????????Shallow_2_1?t?=?new?Shallow_2_1(1998,?4,?16);
????????System.out.println(t.toString());
????????System.out.println(t.equals(t));
????}

????//?無參數構造函數
????public?Shallow_2_1(){

????}

????//?有參數構造函數
????public?Shallow_2_1(int?year,?int?month,?int?day){
????????this.year?=?year;
????????this.month?=?month;
????????this.day?=?day;
????}

????//?生成set?get方法

????public?int?getYear(){
????????return?year;
????}

????public?void?setYear(int?year){
????????this.year?=?year;
????}

????public?int?getMonth(){
????????return?month;
????}

????public?void?setMonth(int?month){
????????this.month?=?month;
????}

????public?int?getDay(){
????????return?day;
????}

????public?void?setDay(int?day){
????????this.day?=?day;
????}

????//?生成toString方法,一般生成toString方法要重寫
????public?String?toString(){
????????return?year?+?"/"?+?month?+?"/"?+?day;
????}

????//?生成equals方法,一般生成equals方法要重寫
????@Override
????public?boolean?equals(Object?obj)?{
????????if(this?==?obj){
????????????return?true;
????????}
????????if(!(obj?instanceof?Shallow_2_1)){
????????????return?false;
????????}
????????Shallow_2_1?tt?=?(Shallow_2_1)obj;
????????return?this.year?==?tt.year?&&?this.month?==?tt.month?&&?this.day?==?tt.day;
????}


}


正在回答

1 回答

嗯優秀

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531142    人
  • 解答問題       6326    個

課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙

進入課程

拿去參考吧

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號