Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
The_Nick
Posts: 132 Joined: Thu May 16, 2013 9:23 am
Contact:
Post
by The_Nick » Wed Sep 18, 2013 4:19 am
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.
Online
admin
Site Admin
Posts: 10061 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Wed Sep 18, 2013 8:35 am
This is invalid because new Outsider.Insider implies that Insider is a static member of Outsider, which it is not.
HTH,
Paul.
If you like our products and services, please help us by posting your
review here .
yuir12
Posts: 22 Joined: Thu Dec 09, 2021 11:23 pm
Contact:
Post
by yuir12 » Thu Feb 24, 2022 1:10 am
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
Online
admin
Site Admin
Posts: 10061 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Thu Feb 24, 2022 1:53 am
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.
If you like our products and services, please help us by posting your
review here .
Users browsing this forum: No registered users and 97 guests