About Question enthuware.ocpjp.v7.2.1421 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1421 :

Post by The_Nick »

Hi everybody,
I have tried this, and I do not know why it does not compile.. it should:

Code: Select all

Outsider.Insider osi = os.new Outsider.Insider();
I understand that Outsider in the right component would be redundant however there are many cases where redundancy is at least syntactically correct..

What do you think about it?

The_Nick.

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 »

This is invalid because new Outsider.Insider implies that Insider is a static member of Outsider, which it is not.

HTH,
Paul.

yuir12
Posts: 22
Joined: Thu Dec 09, 2021 11:23 pm
Contact:

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

Post by yuir12 »

Hello.

I didn't get this: os.Insider implies that Insider class is in package os, which is not the case. Why does it imply package os?

Thanks

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 »

When the compiler sees the token "os.Insider" it can interpret it in two ways - 1. os is a package and Insider is a class in that package. 2. os is a reference variable of some type and Insider is a member of that type.
The compiler resolves this ambiguity in favor of os being a reference variable because of the rules of the Java language.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests