類和對象執行個體1

來源:互聯網
上載者:User

標籤:static   font   show   oid   []   駝峰命名   調用   屬性   sys   

定義姓名,性別,年齡,然後賦值,並建立對象調用方法輸出姓名,性別,年齡

/**
 *
 * public : 代表存取修飾詞
 * class : 類的標識
 * Student : 類名

 * 方法名稱首字母小寫,其餘後面單字首大寫  

 * 帕斯卡:首字母大寫   

 * 駝峰命名法:方法名稱首字母小寫,其餘後面單字首大寫
  */

  public class Student{      // 封裝類型     String name;     //姓名     Chaar sex;        //性別     int age;            //年齡            //顯示資訊方法     public void ShowStudent(){               System.out.println("進入了ShowStuden方法t");               System.out.println("姓名:"+name+"\t性別:"+sex+"\t年齡:"+age);    }                    //用來建立類的對象,然後給屬性賦值,調用方法        //stu就是Student類的一個對象    public static void main(String[] args) {        Student stu=new Student();    //建立對象stu             //賦值             stu.name;     //姓名             stu.sex;        //性別             stu.age;       //年齡                               //調用方法            stu.showStudent();                }            }

 

類和對象執行個體1

聯繫我們

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