aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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 !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MindQ: can you help to explain this.. Thanks!
 
Similar Threads
mock exam question need some help
Question
Super and sub class
Overridding Pls Explain this code
Doubt on program output from overriding