Object 是所有的類別的父類別。
每個類別都會extends Object ,所以程式不要寫,就會自動extends。
所有物件(包括陣列)都實作這個類別的方法。

用法:
只有一個建構子(constructor) Object()。
Object object =new Object();

常用的方法:


 booleanequals(Object obj)
          指示其他某個物件是否與此物件「相等」。



                Object object =new Object();
Object object1 =new Object();
System.out.println(object.equals(object1));//false
Object object2 = object;
System.out.println(object.equals(object2));//true




 StringtoString()
          返回該物件的字元串表示。



Object 類別的 toString 方法返回一個字元串, 該字元串由類別名(物件是該類別的一個實例)、 at 標記符“@”和此物件雜湊碼的無符號十六進製表示組成。 換句話說,該方法返回一個字元串,它的值等於:

getClass().getName() + '@' + Integer.toHexString(hashCode())



System.out.println(object.toString());//java.lang.Object@ecd7e
System.out.println(object1.toString());//java.lang.Object@1d520c4
System.out.println(object2.toString());//java.lang.Object@ecd7e



其它方法:


protected  Objectclone()
          創建並返回此物件的一個副本。
protected  voidfinalize()
          當垃圾回收器確定不存在對該物件的更多參考時,由物件的垃圾回收器調用此方法。
 Class<?>getClass()
          返回此 Object 的運行時類別。
 inthashCode()
          返回該物件的雜湊碼值。
 voidnotify()
          喚醒在此物件監視器上等待的單個執行緒。
 voidnotifyAll()
          喚醒在此物件監視器上等待的所有執行緒。
 voidwait()
          在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法前,導致當前執行緒等待。
 voidwait(long timeout)
          在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法,或者超過指定的時間量前,導致當前執行緒等待。
 voidwait(long timeout, int nanos)
          在其他執行緒調用此物件的 notify() 方法或 notifyAll() 方法,或者其他某個執行緒中斷當前執行緒,或者已超過某個實際時間量前,導致當前執行緒等待。

執行緒相關的方法:
<b; font-family:="" monospace;"="">notify、notifyAll、wait
另章介紹 
<b; font-family:="" monospace;"="">                建製中…
<b; font-family:="" monospace;"="">

<b; font-family:="" monospace;"="">回收器相關的方法:
<b; font-family:="" monospace;"="">finalize()
<b; font-family:="" monospace;"="">
<b; font-family:="" monospace;"="">另章介紹 
<b; font-family:="" monospace;"="">                建製中…
<b; font-family:="" monospace;"="">

取得class 套件名稱:
System.out.println(object.getClass());//class java.lang.Object


複製的方法:
clone()
<b; font-family:="" monospace;"="">另章介紹
<b; font-family:="" monospace;"="">[JAVA]Object-物件的複製使用clone()


JAVA Object API
<b; font-family:="" monospace;"="">Object (Java Platform SE 6)

 
















其它文章

arrow
arrow
    文章標籤
    java 物件 執行緒 object
    全站熱搜

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()