my dog learned polymorphism*
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
Author

Compilation fails

Kefe Abalov
Greenhorn

Joined: Jul 15, 2003
Posts: 4
Given:
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


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation fails
 
Similar Threads
Package level question.
package
error in result
Mock Exam Qn.(What is the result)