Page 1 of 1
About Question enthuware.ocpjp.v7.2.1421 :
Posted: Tue Mar 12, 2013 5:55 am
by alex
Hi,
Why an option Insider in = os.new Insider(); is illegal?
Compiler allows me to insert this line.
Description says next: You cannot refer to Insider class directly. For all purposes, its name is Outsider.Insider.
But I can refer to Insider class directly.
Regards,
Alex
Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Tue Mar 12, 2013 10:11 am
by admin
Are you sure you are running the code exactly as given? I just tried it and it didn't compile.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Sat Mar 16, 2013 8:55 pm
by alex
Hi Paul,
Sorry, there was one blooper.
Actually I could use Insider in = os.new Insider(); if I would have appropriate import Outsider.Insider;
But that is not mentioned in context.
Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Mon Jul 22, 2013 4:47 pm
by renatumb
Depends on the context, but
is not totally illegal.
because If you imported also the Inner Class, it would work, something as such:
import Outter.* ;
http://docs.oracle.com/javase/tutorial/ ... epkgs.html
I think you should change a little bit the explanation, because it causes some confusion...

Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Mon Jul 22, 2013 6:54 pm
by admin
I am not sure I follow what you are saying. Can you give complete code listing to explain what you mean? As per the code given in the question, Insider in = os.new Insider() is invalid.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Mon Jul 22, 2013 7:42 pm
by renatumb
Sorry, I forgot to say that is necessary the package, as such: import package.class.*
I wrote this class to show you what i mean:
Code: Select all
package p1;
import p1.Outter.*; // This is necessary, wihout it, Inner Classes don't work !!
// It is importing only the Inner Classes, like "import static"
public class TestClass {
public static void main(String[] args) {
Outter out = new Outter();
InnerPublic in1 = out.new InnerPublic(); // OK
InnerDefault in2 = out.new InnerDefault(); // dont work out of p1
InnerProtected in3 = out.new InnerProtected(); // dont work out of p1
//InnerPrivate in4;
}
}
Code: Select all
package p1;
import p1.Outter.*; // This is necessary, wihout it, Inner Classes don't work !!
// It is importing only the Inner Classes, like "import static"
public class TestClass {
public static void main(String[] args) {
Outter out = new Outter();
InnerPublic in1 = out.new InnerPublic(); // OK
InnerDefault in2; // dont work out of p1
InnerProtected in3; // dont work out of p1
//InnerPrivate in4;
}
}
Re: About Question enthuware.ocpjp.v7.2.1421 :
Posted: Tue Jul 23, 2013 7:58 am
by admin
I see what you are saying. You are right. This has now been added to the explanation.
thank you for your feedback,
Paul.