包的使用和對象的建立

package com.company; // 包 包名

/*

? ? ? ? public? 公有的,公共的? 其他的程序都可以訪問,最大的極限,其他程序都能訪問? ? ? ? class? 類? ? ? ? Main? 類的名稱 ,隨便取名字,最好有意義,一般要求首字母大寫*/

public class Main {

/*

? ? ? ? public? 公有的,公共的? 其他的程序都可以訪問,最大的極限,其他程序都能訪問? ? ? ? static? 靜態(tài)的? ? ? ? ? 沒有對象也可以調(diào)用,屬于公共資源? ? ? ? void? ? ? 空? ? ? ? ? 方法的返回值,由于main是主方法,不需要給任何程序返回內(nèi)容,因此就寫空? ? ? ? main? ? ? 主要的? ? ? ? 方法的名字,可以隨便取,但是入口主方法只能寫成main ,自定義的方法名可以自己取,建議有意義,首字母小寫,駝峰命名法

? ? ? ? (string[] args)? ? ? ? 方法的參數(shù) String[] -> 參數(shù)的類型 args? 數(shù)組的名字*/

? ? public static void main(String[] args) {

//? 對象的創(chuàng)建? 類型? 對象名 = new 類名()

? ? ? ? Student xujinwei =new Student();

? ? ? ? //? 屬性的賦值

? ? ? ? xujinwei.name ="徐大大" ;

? ? ? ? xujinwei.age =20 ;

? ? ? ? xujinwei.sex ='男' ;

? ? ? ? xujinwei.high =180.00;

? ? ? ? xujinwei.height =100.88;

? ? ? ? //? 屬性的調(diào)用

? ? ? ? System.out.println(xujinwei.name);

? ? ? ? System.out.println(xujinwei.age);

? ? ? ? System.out.println(xujinwei.sex);

? ? ? ? System.out.println(xujinwei.high);

? ? ? ? System.out.println(xujinwei.height);

? ? ? ? //? 方法的調(diào)用

? ? ? ? xujinwei.eat();

? ? ? ? xujinwei.play();

? ? ? ? xujinwei.sleep();

? ? }

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容