Object

From Abap2Java

Jump to: navigation, search

ABAP

To do...

See also:
CLASS, OO

Java

The Object can be used similar to the pointer to a pointer (**ppv) in C++. However, every Object derives implicitly from Object (which is not the case in C++). For example the Vector in Java 1.4.2 only accepts Objects as content and will only return objects as result. They need to be casted before used.

Every object can overwrite methods defined in the class object. Some examples:

class MyClass implements |Cloneable{
   public Object clone() throws CloneNotSupportedException {
      Object obj = super.clone();
      // do custom cloning
      return obj;
   }
   // will be called when Object is accessed in String context
   // e.g. System.out.print (obj);
   public String toString() {
      return "String representation";
   }
   // overwrite to influence the equals method
   // used for sorting e.g. see also comparable
   public boolean equals(Object obj) {
      // compare
      return b;
   }
}

See also
comparable,clone

External links
Java JDK 1.4.2 Object
Creating Object Wikibooks Java Programming

Personal tools