About Question enthuware.ocpjp.v7.2.1421 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
alex
Posts: 42
Joined: Tue Feb 12, 2013 4:35 pm
Contact:

About Question enthuware.ocpjp.v7.2.1421 :

Post 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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post by admin »

Are you sure you are running the code exactly as given? I just tried it and it didn't compile.

HTH,
Paul.

alex
Posts: 42
Joined: Tue Feb 12, 2013 4:35 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post 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.

renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post by renatumb »

Depends on the context, but

Code: Select all

Insider in = os.new Insider()
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... ;)

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post 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.

renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post 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;
    }
}

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1421 :

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests