Please see the below code
class Exam{
protected
String diff = " easy ";
public void printDiff(){
System.out.println(this.diff);
}
}
public class Test1 extends Exam{
private String diff = " killing ";
public static void main(String[] args){
Test1
test = new Test1();
test.printDiff();
System.out.println(test.diff);
}
}
it is giving output as "easy" and "killing" I am invoking the super class method with subclass object, here object type is subclass only but at the time of execution why it is considering super class variable? and I tried this way also like I override parent class method in subclass and I tried to execute and it is printing "killing" 2 times..why it is?can anybody explain exactly what is happening here?
Thanks in advance.