aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Protected and Default members, different packages...Please explain... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Protected and Default members, different packages...Please explain..." Watch "Protected and Default members, different packages...Please explain..." New topic
Author

Protected and Default members, different packages...Please explain...

Boris Mechkov
Ranch Hand

Joined: May 13, 2011
Posts: 72

First of all hello to all posters here. I have been reading this forum for 2 years now but just registered because i am studying really hard for the OJCP 6 exam...So thanks to all of you around here who decide to help (and the rest as well)...

This question comes from the K&B Book, Chapter 10 Self Exam questions...In a nutshell:



Can someone explain why the first two Comp. Errors occur (CE)...I thought we are looking at "a" and "b" from a FOO instance, so we should have access to them. (even though the Foo instance is in a different package)...
Forgive if this is obvious but i have read 240 pages from the book for the past 9 hours...


OCPJP 6
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

No, if you're in the Fiz class, you're in the B package, regardless of what you're inheriting from.

So access to a is impossible, and access to b is only possible via inheritance (i.e. you can't access it via a reference to the superclass).
Boris Mechkov
Ranch Hand

Joined: May 13, 2011
Posts: 72

Matthew Brown wrote:No, if you're in the Fiz class, you're in the B package, regardless of what you're inheriting from.

So access to a is impossible, and access to b is only possible via inheritance (i.e. you can't access it via a reference to the superclass).


Hmmm, agreed. I was expecting to see something like Foo f= new Fiz(); or Fiz f = new Fiz(); and then it would have made more clear sense.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected and Default members, different packages...Please explain...