class ConstructorTry {
public static void main(String[] args) {
ConstructorTry02 cons01 = new ConstructorTry02("lord");
System.out.println(cons01.name);
System.out.println(cons01.age);
System.out.println("**********");
ConstructorTry02 cons02 = new ConstructorTry02(18);
System.out.println(cons02.name);
System.out.println(cons02.age);
System.out.println("**********");
ConstructorTry02 cons03 = new ConstructorTry02("lord", 18);
System.out.println(cons03.name);
System.out.println(cons03.age);
System.out.println("**********");
ConstructorTry02 cons04 = new ConstructorTry02();
System.out.println(cons04.name);
System.out.println(cons04.age);
System.out.println("**********");
/*
lord
-1
**********
anoymous
18
**********
lord
18
**********
anoymous
-1
**********
*/
}
}
class ConstructorTry02 {
String name;
int age;
ConstructorTry02(String name, int age){
this.name = name;
this.age = age;
}
ConstructorTry02(int age){
this("anoymous", age);
}
ConstructorTry02(String name){
this(name, -1);
}
ConstructorTry02(){
this("anoymous", -1);
}
}
Java Constructor
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門辜限,熙熙樓的掌柜王于貴愁眉苦臉地迎上來皇拣,“玉大人,你說我怎么就攤上這事薄嫡⊙跫保” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵毫深,是天一觀的道長吩坝。 經(jīng)常有香客問我,道長哑蔫,這世上最難降的妖魔是什么钉寝? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮闸迷,結(jié)果婚禮上嵌纲,老公的妹妹穿的比我還像新娘。我一直安慰自己腥沽,他們只是感情好逮走,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著今阳,像睡著了一般师溅。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上盾舌,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼铸史!你這毒婦竟也來了鼻疮?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布刻两,位于F島的核電站,受9級特大地震影響滴某,放射性物質(zhì)發(fā)生泄漏磅摹。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一壮池、第九天 我趴在偏房一處隱蔽的房頂上張望偏瓤。 院中可真熱鬧,春花似錦椰憋、人聲如沸厅克。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽证舟。三九已至,卻和暖如春窗骑,著一層夾襖步出監(jiān)牢的瞬間女责,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- org.springframework.beans.factory.UnsatisfiedDependencyEx...
- Constructor類理解 這里Constructor掖疮,我們知道是構(gòu)造函數(shù)為什么是數(shù)組形式的呢初茶?因為可能有多個構(gòu)...
- 這篇文章總結(jié)了Java使用構(gòu)造函數(shù)中最常遇到的五個問題! 1 為什么調(diào)用子類的構(gòu)造方法的時候浊闪,默認會調(diào)用父類的構(gòu)造...
- 關(guān)閉SIP 重啟電腦恼布,按住Command+R(直到出現(xiàn)蘋果標志)進入Recovery Mode(恢復(fù)模式)左上角菜...