Here is the Question
Source:http://www.hitechskill.com/testengine.jsp
Which one of the following is the simplest way to print the value of variable text at line no. 18?Select one correct answer.
1 class Message
2 {
3
String text="Hello1";
4 }
5 class Super
6 {
7 Message msg=new Message();
8 }
9 class inheritance extends Super
10 {
11 public static void main(String arg[])
12 {
13 inheritance i=new inheritance();
14 i.print();
15 }
16 public void print()
17 {
18 //Here
19 }
20 }
Choice 1 System.out.println(msg.text);
Choice 2 System.out.println(super.msg.text);
Choice 3 System.out.println(Message.text);
Choice 4 System.out.println(text);
I thought like this:
choice 1 is the only correct answer.
But when I run on my machine if I insert
choice2 also at line 18 it is compiling fine and giving same o/p.
Can anybody please explain what does
super.msg.txt indicate?