我对对象和引用的理解
生活随笔
收集整理的這篇文章主要介紹了
我对对象和引用的理解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注:看了靖寶華的文章《對"類"和"對象"的深度揣摩與思考...(java初學者)》,我想說一下,在創建一個類對象的情況下,我對"對象"和"引用"的一些理解。歡迎一起討論!
(引用部分原文代碼)
class?Student???????????????
{
????public?String??strname;?????
????public?int?????intage;?????
????public?boolean?blsex;???????
} public?class?StudentDemo{
????public?static?void?main(String?[]?args){
????????Student?aStudent;??????????
????????aStudent=new?Student();?????
?????????
????}
} 1)?
Student aStudent;?
//這里只是聲明了一個指向類Strudent的引用變量,aStudent可以指向Student對象?
2)?
new Student?
以類Student為模板,在堆空間中創建一個Student類對象?
3)()?
末尾的()在創建對象之后調用類Student的構造函數,對對象進行初始化。如果你沒有寫構造函數,則調用默認的構造函數?
4)=?
"="使對象引用aStudent指向剛才創建的類Student對象?
本文轉自BlogJavaOo緣來是你oO的博客,原文鏈接:我對"對象"和"引用"的理解,如需轉載請自行聯系原博主。
(引用部分原文代碼)
class?Student???????????????
{
????public?String??strname;?????
????public?int?????intage;?????
????public?boolean?blsex;???????
} public?class?StudentDemo{
????public?static?void?main(String?[]?args){
????????Student?aStudent;??????????
????????aStudent=new?Student();?????
?????????
????}
} 1)?
Student aStudent;?
//這里只是聲明了一個指向類Strudent的引用變量,aStudent可以指向Student對象?
2)?
new Student?
以類Student為模板,在堆空間中創建一個Student類對象?
3)()?
末尾的()在創建對象之后調用類Student的構造函數,對對象進行初始化。如果你沒有寫構造函數,則調用默認的構造函數?
4)=?
"="使對象引用aStudent指向剛才創建的類Student對象?
本文轉自BlogJavaOo緣來是你oO的博客,原文鏈接:我對"對象"和"引用"的理解,如需轉載請自行聯系原博主。
總結
以上是生活随笔為你收集整理的我对对象和引用的理解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人工智能:看似很美,却暗藏泡沫
- 下一篇: MongoDB(课时18 修改器)