• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class

 
xie li
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shawnne James
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think A & D are valid.

With Best Regards,

Sachin Dimble.
 
Kian Ng
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bro, i think D is wrong cos inner class cannot have static method definition..
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
xie li
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic