File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compilation fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compilation fails " Watch "Compilation fails " New topic

Compilation fails

Kefe Abalov

Joined: Jul 15, 2003
Posts: 4
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.println(�x = � + x);
5. }
6. }
What is the result?
A. x = 0
B. x = 42
C. Compilation fails because of an error in line 2 of class Test2.
D. Compilation fails because of an error in line 3 of class Test1.
E. Compilation fails because of an error in line 4 of class Test2.
Answer: C
why not E
i think E is correct
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
E is correct. The code does not compile since x has default access. So it is not visible outside the package even not in a subclass. Variable x should be marked protected or public, in order the code to compile.

Miki<br /> <br />SCJP 1.4, SCBCD 1.3
I agree. Here's the link:
subject: Compilation fails
It's not a secret anymore!