About Question enthuware.ocpjp.v8.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
schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

About Question enthuware.ocpjp.v8.2.1421 :

Post by schchen2000 »

Code: Select all

class Outsider{

        public static class Insider{ // Line # 1



        }

}

class TestClass{

        public static void main(String[] args){

                Outsider os = new Outsider();

                Outsider.Insider in = Outsider.new Insider(); // Line # 2

        }

}
I've added 2 comments in the above code snippet.

The last answer option available to Problem # 53 says "You cannot refer to Insider class directly. Outsider.new Insider() is wrong as well because Insider is not static;"

I wanted to test that so I made changes and came up with Line # 2 above.

In order to test the right-hand side of the statement on Line # 2, I've modified the original code in the question by adding

"Outsider."

to

"Insider in = Outsider.new Insider()"

I ran it and Insider not being static did not seem to be the problem.

I instead encountered

"error: cannot find symbol
Outsider.Insider in = Outsider.new Insider();

symbol: variable Outsider
location: class TestClass
1 error
"

with or without "static" being added on Line # 1.

The symbol the error message refers to is "Outsider" on the right-hand side.

Am I missing something here? Thanks.

Schmichael

PS

Both classes were in the same file when being run.

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

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

Post by admin »

To create a new instance of a static nested class, the syntax would be new Outsider.Insider();
The statement in the explanation is referring to the Outside dot syntax which is used for accessing a static member of Outside class. But I can see that it can easily be misinterpreted to imply that Outsider.new Insider() would be valid if Insider were static.
I have updated the explanation to make it clear.

thank you for your feedback!
Paul.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

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

Post by schchen2000 »

admin wrote:To create a new instance of a static nested class, the syntax would be new Outsider.Insider();
The statement in the explanation is referring to the Outside dot syntax which is used for accessing a static member of Outside class. But I can see that it can easily be misinterpreted to imply that Outsider.new Insider() would be valid if Insider were static.
I have updated the explanation to make it clear.

thank you for your feedback!
Paul.
Thanks, Paul. Appreciate it!

Schmichael

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests