inheritance - new keyword in java -


new java, , still struggling new keyword , inheritance:

public class a1 {     void a_method (){         system.out.println("inside a1 method");     } } 

public class a2 extends a1{     void a_method(){         system.out.println("inside a2 method");     } } 

public class testa1a2 {      public static void main(string[] args) {          a1 a1 = new a1();         a1 a2 = new a2();  //not sure if created object of a1 or a2         a2 a3 = new a2();          a1.a_method();         a2.a_method();         a3.a_method();      } } 

i struggling understand new keyword , if in above code:

a1 a2 = new a2();  //not sure if created object of a1 or a2 

will a2 object of a1 or a2? output can see called method of a2, dont new keyword. , a2 extending a1, possile call method of a1??

a1 a2 = new a2();  

this code creates a2 object can access methods of a1 class a2. if method overriden in a2, method of a2 called.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -