JAVA練習題,

來源:互聯網
上載者:User

JAVA練習題,

package cn.person.www;

  public  class  person {            public  int  id;      public  String name;      public  int  age;      public  String city;      public  String introduce() {          return  "我是"  + id +  "號, 叫  "  + name +  ", 今年"  + age +  "歲了, 來自"  + city ;      }   public  person( int  id,String name, int  age,String city) {       this .id=id;  //this關鍵字,表達的含義是當前對象 .表示當前對象的某個調用       this .name=name;       this .age=age;       this .city=city;   }           }

 package cn.person.www;

  public  class  Demoperson {       public  static  void  main(String[] args) {          // TODO Auto-generated method stub          person p1= new  person( 001 , "劉備" , 40 , "北京" );          person p2= new  person( 002 , "關羽" , 37 , "北京" );          person p3= new  person( 003 , "張飛" , 45 , "北京" );          person p4= new  person( 004 , "諸葛亮" , 25 , "北京" );                    System.out.println(p1.introduce());          System.out.println(p2.introduce());          System.out.println(p3.introduce());          System.out.println(p4.introduce());                }  }

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.