About Question enthuware.ocpjp.v7.2.1421 :
Moderators: Site Manager, fjwalraven
-
- Posts: 42
- Joined: Tue Feb 12, 2013 4:35 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1421 :
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
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
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
Are you sure you are running the code exactly as given? I just tried it and it didn't compile.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 42
- Joined: Tue Feb 12, 2013 4:35 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
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.
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.
-
- Posts: 47
- Joined: Mon Apr 08, 2013 7:55 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
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...
Code: Select all
Insider in = os.new Insider()
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...

-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
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.
HTH,
Paul.
-
- Posts: 47
- Joined: Mon Apr 08, 2013 7:55 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
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:
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;
}
}
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1421 :
I see what you are saying. You are right. This has now been added to the explanation.
thank you for your feedback,
Paul.
thank you for your feedback,
Paul.
Who is online
Users browsing this forum: No registered users and 5 guests