aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner  class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner  class" Watch "inner  class" New topic
Author

inner class

xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
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

Joined: Oct 27, 2005
Posts: 13
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

Joined: Dec 07, 2005
Posts: 100
I think A & D are valid.

With Best Regards,

Sachin Dimble.
Kian Ng
Greenhorn

Joined: Dec 18, 2005
Posts: 17
bro, i think D is wrong cos inner class cannot have static method definition..
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class