Thursday, 12 February 2015

Instance Initializer Block

  1. class Bike7{  
  2.     int speed;  
  3.       
  4.     Bike7(){System.out.println("speed is "+speed);}  
  5.    
  6.     {speed=100;}  
  7.        
  8.     public static void main(String args[]){  
  9.     Bike7 b1=new Bike7();  
  10.     Bike7 b2=new Bike7();  
  11.     }      
  12. }  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
    1. class A{  
    2. A(){  
    3. System.out.println("parent class constructor invoked");  
    4. }  
    5. }  
    6. class B2 extends A{  
    7. B2(){  
    8. super();  
    9. System.out.println("child class constructor invoked");  
    10. }  
    11.   
    12. {System.out.println("instance initializer block is invoked");}  
    13.   
    14. public static void main(String args[]){  
    15. B2 b=new B2();  
    16. }  
     

No comments:

Post a Comment