aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock Exam Qn.(What is the result) 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 "Mock Exam Qn.(What is the result)" Watch "Mock Exam Qn.(What is the result)" New topic
Author

Mock Exam Qn.(What is the result)

Chandrakanth
Ranch Hand

Joined: Aug 16, 2005
Posts: 60
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.
Poonam Thawani
Greenhorn

Joined: Oct 11, 2005
Posts: 13
Its 42.
Chandrakanth
Ranch Hand

Joined: Aug 16, 2005
Posts: 60
42 is not the answer.

I am confused with these two...
When i run the program i am getting the answer as 'E', but the Mock Exam gives the answer as 'C'.
Just wanted to make sure, the answer is E or not

C. Compilation fails because of an error in line 2 of class Test2.
E. Compilation fails because of an error in line 4 of class Test2.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
the variable x has a default access


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163


Hi here, test1.Test1 class is not imported.
so line-2 gives compilation error.
Sowjanya Chowdary
Ranch Hand

Joined: Aug 22, 2005
Posts: 35
I am also getting answer as E.
Because, x is not declared public in Test1.java, so it can't be accessed outside the package.

Answer can't be C because, when using a class outside a package, we can either import that package or use fully-qualified-name.
Here in line 2 of Test2.java, we are using fully-qualified-name of Test1 class as "test1.Test1.java".

-Amrutha
vivekkumar sharma
Ranch Hand

Joined: Dec 21, 2005
Posts: 70
Originally posted by Amrutha Chowdary:
Because, x is not declared public in Test1.java, so it can't be accessed outside the package.


-Amrutha


Hi ,
it will work with protected as well
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Exam Qn.(What is the result)