Thursday, January 13, 2011

This and Super

This keyword is useful when you need to refer to instance of the class from its method. This keyword helps us to avoid name conflicts as we can see in the program that we have declare the name of instance variable and local variable same. Now to avoid the confliction between them we use this keyword.


this is used for pointing the current class instance it can be used with variables or methods . this is cannot used inside the static method.



Super keyword is used for pointing the super class instance. Either variables or methods.



objects creation in java


In java objects are created in several ways they are
  • using new operator
    ex: Employe obj = new Employe();

  • using factory methods
    ex: NumberFormat obj = NumberFormat.getNumberInstance();

  • using newInstance() method
    ex: class c = class.forName(“Employe”);
    Employe obj = c.newInstance();

  • using cloning : creating bit wise exact copy of an object is called cloning
    ex:Employe e1 = new Employe();
    Employee e2 = e1.clone();

No comments:

Post a Comment