wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Classes 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 Classes" Watch "Inner Classes" New topic
Author

Inner Classes

Raef Kandeel
Ranch Hand

Joined: Aug 05, 2007
Posts: 87
In a study guide, I met the following question:-

package foo;

public class Outer {
public static class Inner {
}
}

Which statements are true?
A.An instance of the Inner class can be constructed with �new Outer.Inner()�
B.An instance of the Inner class cannot be constructed outside the package foo.
C.An instance of the inner class can only be constructed from within the outer class.
D.From within the package bar, an instance of the inner class can be constructed with the �new Inner()�
Answer: A

I tried the following code:-

import foo.Outer;
import static foo.Outer.Inner;

public class Test {
public static void main (String args []) {
new Inner();
}
}

and it worked, which suggests that the answer �D� could be correct too.


SCJP, SCWCD
Charley Watson
Greenhorn

Joined: Mar 19, 2005
Posts: 10
IMHO, with certification exams, it is always important not to infer more than is stated. Since the question doesn't include the static imports you've added in your solution, there is a single correct answer to the question. Also, I think the current exam practice is to include the correct number of replies which apply. As in :

Which two of the following four are true:
Raef Kandeel
Ranch Hand

Joined: Aug 05, 2007
Posts: 87
I tried the following code without the static import and it worked too.


import foo.Outer.Inner;

public class Test {
public static void main (String args []) {
new Inner();
}
}
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy ranchers,

are you sure what imports really do?

When you type
package bar;
import foo.Outer.Inner;
class XYZ(...)
new Inner();


it is just the same as if you wrote
package bar;
class XYZ(...)
new foo.Outer.Inner();

without importing. This is not what answer D demanded.


Yours,
Bu.


all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Classes