In the following question, c and e are correct. I thought classes could not be declared private? In fact the Exam Cram book states this in the cram sheet? What am I missing? I can only assume that inner classes support private... 2. Given: public class OuterClass { private double d1 = 1.0; //insert code here } You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.) class InnerOne{ public static double methoda() {return d1;} } a. public class InnerOne{ static double methoda() {return d1;} } b. private class InnerOne{ double methoda() {return d1;} } c. static class InnerOne{ protected double methoda() {return d1;} } d. abstract class InnerOne{ public abstract double methoda(); }
djroberts
Greenhorn
Joined: Sep 20, 2000
Posts: 6
posted
0
Sorry the letters are one off. a is the first one and e is the last one like follows:
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(); }
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
posted
0
Member inner class whether static or non static, ( ie. inner class declared in class scope ) can have private as well as protected access modifiers. The reason is such classes are kind of equivalent to other members ( fields and methods ) of the class. But local inner class ( ie. inner class defined in method) cannot have any access modifier. This is again consistent with Java's treatment of local variables. HTH, Paul.
Cos in d the inner class is static, Richard. And there's no way it can figure out which instance variable it should refer to in the return statement. It's just like how the good ol' public static void main(String[] args) can't access your non-static members. Cheers
Originally posted by Richard Huang: Thanks, Paul. Can I ask why 'd' is wrong?