• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner Classes

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic