Method overriding and Shadowing
Posted: Tue Apr 26, 2016 9:56 am
Can somone please tell me why the following snippet prints
=> 200
=> 100
instead of
=> 200
=> 300
Where am i missing the point ?
=> 200
=> 100
instead of
=> 200
=> 300
Where am i missing the point ?
Code: Select all
class FieldScope2 {
public int testA = 100;
public void methodA(){
testA =+ 100;
}
}
public class FieldScope extends FieldScope2 {
public int testA = 200;
public void methodA(){
testA =+ 100;
}
public static void main(String [] argv ){
FieldScope fieldScope = new FieldScope();
System.out.println( fieldScope.testA ); // => 200 ok
fieldScope.methodA();
System.out.println( fieldScope.testA ); // => 300 Expected
}
}