java 中的终极对象 Object

来源:互联网 发布:开淘宝店怎么找快递 编辑:程序博客网 时间:2024/05/07 06:34

java 中的终极对象 Object
在java中所有的类都是从Object 继承过来的
Object对象 的方法
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one. 


           
 int hashCode()
          Returns a hash code value for the object. 

 java.lang.String toString()
          Returns a string representation of the object. 

getClass()

当某个对象是以Objiect类型来引用的时候,java会把他当作Object的实例,你只能调用Object的方法
 Object vampire =new Vampire();
  byte i=1;
  vampire.frighten(i);
  出错:The method frighten(byte) is undefined for the type Object
  
任何从arrayList中取出的东西都会当成Object类型而不管它原来是什么。 

原创粉丝点击