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
posted
0
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
posted
0
Hi, I also agree with Viji. C,E are correct. regards deekasha
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
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.