Hi,
in the following code while constructing A, why the call to the method m refers to the one in class B? What is the rule that governs this? ( I understand m is overrided)
- Thanks
class A {
int x=10;
void m(){System.out.println("A"+ x);}
A(){
System.out.println("constructing A");
m();}
}
class B extends A {
int x=20;
void m(){System.out.println("B"+ x);}
B(){
System.out.println("constructing B"); }
}
public class Try{
public static void main (
String args[]) {
A newa = new B();
}}