What will the following code print when compiled and run?
class MyClass{ //w w w .j av a2s . c o m int x = 10; static int y = 20; } class MySubClass extends MyClass{ int x = 30; static int y = 40; } public class Main { public static void main (String [] args) { System.out.println(new MySubClass().x+ ", "+ new MySubClass().y); } }
Select 1 option
Correct Option is : D
System.out.println (new MySubClass ().x);
The reference is of type MySubClass and so MySubClass's x will be accessed.