File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes Markus, exam 1, Q43 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Reply locked New topic

Markus, exam 1, Q43

Jeff L.

Joined: Sep 02, 2003
Posts: 8
What will be the result when you try to compile and run the following code?
private class Base{
int i = 100;
public class Pri extends Base{
static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
1) Error at compile time
2) 200
3) 100 followed by 200
4) 100
The answer listed is 1), because the code doesn't compile, presumably assuming that the java filename is, but why assume that? Why couldn't the file be named I compiled a Java class with the public class listed second just this afternoon and it worked fine.
Jeff L.

Joined: Sep 02, 2003
Posts: 8
Oops! I should have said I tried earlier to compile where the public class was listed after another package scope class. Apparantly, package classes and private classes are treated differently. Private classes cause an error "modifyier private not allowed here", while package classes compile just fine. IMO, this aspect of Java is silly, but the question was correct about there being a compiler error. My bad.
It is sorta covered in the JavaRanch Style Guide.
subject: Markus, exam 1, Q43
Similar Threads
Default constructor !!!!
inheriting variables
Again forward references
Marcus Exam 1