Once again I am confused...
I think Instance variables invocation depends upon the reference type...
where as method calling depends upon the object type...
Then the anser will be Geography....But actual answer is Mathematics...
(MainTest mt = new
Test();
mt.takeTest1();
here it prints Mathematics...it is fine...)
class MainTest {
protected
String subject1="Mathematics";
protected void takeTest1(){
System.out.println(subject1);
}
}
public class Test extends MainTest{
protected String subject1="Geography";
public static void main(String... args) {
Test test1 = new Test();
test1.takeTest1();
}
}
Your Answer
Compilation Error
Runtime Exception
Mathematics
Geography