Page 1 of 1

About Question enthuware.ocpjp.v7.2.1421 :

Posted: Wed Sep 18, 2013 4:19 am
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.

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

Posted: Wed Sep 18, 2013 8:35 am
by admin
This is invalid because new Outsider.Insider implies that Insider is a static member of Outsider, which it is not.

HTH,
Paul.

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

Posted: Thu Feb 24, 2022 1:10 am
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

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

Posted: Thu Feb 24, 2022 1:53 am
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.