[Logo]
Forums Register Login
inner class
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 line2. Which two inner class declarations
are valid? (Choose Two)

A. static class InnerOne {
public double methoda() {return d1;}
}
B. static class InnerOne {
static double methoda() {return d1;}
}
C. private class InnerOne {
public double methoda() {return d1;}
}
D. protected class InnerOne {
static double methoda() {return d1;}
}
E. public abstract class InnerOne {
public abstract double methoda
I would say that the two correct answers are C and E.

The others are not valid because they are trying to access in a static context a non-static variable (d, in the outer class, is a non-static member variable).
I think A & D are valid.

With Best Regards,

Sachin Dimble.
bro, i think D is wrong cos inner class cannot have static method definition..
Shawnne is correct in saying that options A and B won't work because they are trying to reference a non-static variable (d1) from a static context. Kian is correct in saying that option D won't work because an inner class cannot have a static method.

So assuming that line 2 had an equals sign for the assignment, and the abstract method in option E had parentheses and a semicolon, along with a closing brace for the inner class...
[ December 19, 2005: Message edited by: marc weber ]
thank you
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 16, 2017 00:22:53.