GeeCON Prague 2014*
The moose likes Mock Exam Errata and the fly likes MindQ: can you help to explain this.. Thanks! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "MindQ: can you help to explain this.. Thanks!" Watch "MindQ: can you help to explain this.. Thanks!" New topic
Author

MindQ: can you help to explain this.. Thanks!

Jenny Hua
Greenhorn

Joined: Jul 24, 2001
Posts: 8
in MindQ's mock test: http://www.javaranch.com/maha/_Mock_Exams/MindQ_s_Sun_Certified_Java_Programmer_Practice_Test.htm
question #35:
class Super
{ int index = 5;
public void printVal()
{ System.out.println( "Super" );
}
}
class Sub extends Super
{ int index = 2;
public void printVal()
{ System.out.println( "Sub" );
}
}
public class Runner
{ public static void main( String argv[] )
{ Super sup = new Sub();
System.out.print( sup.index + "," );
sup.printVal();
}
}
The answer is :
The code compiles and "5, Sub" is printed to standard output.
I just don't understand why 1 value comes from super, the other comes from sub?? thank you in advance !!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MindQ: can you help to explain this.. Thanks!