File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun's sample quest #2 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Sun Watch "Sun New topic
Author

Sun's sample quest #2

bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Can anyone explain this one. I was a little confused by it. I will hold on giving the answer they have so you can try it yourself first, in case you haven't looked at it yet.
2. Given:
1.public class OuterClass {
2. private double d1 = 1.0;
3. //insert code here
4.}
You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)
A.class InnerOne{
public static double methoda() {return d1;}
}
B.public class InnerOne{
static double methoda() {return d1;}
}
C.private class InnerOne{
double methoda() {return d1;}
}
D.static class InnerOne{
protected double methoda() {return d1;}
}
E.abstract class InnerOne{
public abstract double methoda();
}
Thanks for the help!
Bill
Viji Bharat
Ranch Hand

Joined: Sep 18, 2000
Posts: 101
Bill:
I think C and E are correct.
Reasoning:
Choice A - Incorrect because static method methoda() cannot access non-static var d1
Choice B - Incorrect - same as choice A
Choice C - Correct - Inner class can be declared private and methods in inner class as in this case have access to member vars of outer class
Choice D - Incorrect - d1 cannot be accessed inside static class
Choice E - Correct
HTH
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi,
I also agree with Viji.
C,E are correct.
regards
deekasha
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Bill,
A and B are wrong as Inner Classes cannot declare static initializers or members unless they are compile time constants. JLS§8.1.2
D is wrong because non-static variables cannot be accessed from a static context.
Which leaves C and E as the correct answers.


------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
jQuery in Action, 2nd edition
 
subject: Sun's sample quest #2
 
Threads others viewed
Inheritance from inner Class
Sun Test Question !!!!!!!!!!!
Can inner classes be private?
inner class questoin
inner class
MyEclipse, The Clear Choice