Saturday, 13 January 2018

4.12 Final, This and Anonymous object


Final variable - Constant variable

Final Method - You cannot override a final method.

Final Class - You can't extend a final class

this keyword - represents the current instance
this.x=x;

this is use to call current class constructor
class A{  
A()
    {
   System.out.println("hello a");
    }  
A(int x)
   {  
   this();  
   System.out.println(x);  
   }  
}  
class Test{  
public static void main(String args[])
  {  
  A a=new A(10);  

  }
}  

Anonymous object 
new obj.show() - this will take memory only in heap not in stack and it will be easy for garbage collection.

No comments:

Post a Comment