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.
Originally posted by MuraliRam Narasimhan: ... Is using "test1.Test1 " is not valid one ?
That part is okay. The problem is that the variable x has default ("package") access, so it's not available in test2.Test2. The answer should be E (confirmed by testing). [ December 08, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
uzma Akbar
Ranch Hand
Joined: Sep 21, 2005
Posts: 40
posted
0
I agree with Marc Weber. Though the variable is static but it has package level access so any subclass accessing in a different package will end up at compilor error.
If you are getting answer C in addition to E. The reason being your compilor being unable to locate the file. To rectify that copy the test1 folder in the test2 folder and then javac -classpath . test2/Test2.java
This is one way to do it but there are different ways to include files or folders in class path.
I hope this will help
Uzma
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.