C-4 一個標準的學生類的代碼及測試

來源:互聯網
上載者:User

標籤:

 1 /* 2 標準代碼 3  4 學生類: 5     成員變數:name,age 6     構造方法:無參,帶兩個參 7     成員方法:getXxx()/setXxx(),show 8      9 給成員變數賦值:10   ①setXxx()靈活性高11   ②構造方法。12   13 輸出成員變數值:14   ①getXxx()靈活性高15   ②通過調用show()方法。16 */17 18 class Student{19     private String name;20     private int age;21     22     public Student(){23     24     }25     26     public Student(String name,int age){27         this.name = name;28         this.age = age;29         30     }31     32     public String getName(){33         return name;34     }35     36     public int getAge(){37         return age;38     }39     40     public void setName(String name){41         this.name = name;42     }43     44     public void setAge(int age){45         this.age = age;46     }47     48     public void show(){49         System.out.println(name+"----"+age);50     }51 }52 53 class StudentTest2{54     public static void main(String[] args){55     //無參構造+setXxx ①+①56     Student s1 = new Student();57     s1.setName("小懶");58     s1.setAge(99);59     System.out.println(s1.getName()+"---"+s1.getAge());60     //①+②61     s1.show();62     63     //構造方法給值 ②+①64     Student s2 = new Student("小皮",99);65     System.out.println(s2.getName()+"---"+s2.getAge());66     //②+②67     s2.show();68     }69 }

 

C-4 一個標準的學生類的代碼及測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.