Link to home
Start Free TrialLog in
Avatar of Shantanu
Shantanu

asked on

Porblem on class scope

Let A represent the access scope of a protected field in a Java class and B represent the access scope of a package-scoped field in that class. Which of the following best represents the relationship between A and B?

 A is a subset of B
 A is a superset of B
 A is equal to B
 (A union B) is not equal to (A intersection B)
 There is no relation between A and B

please help me out
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yoren
yoren

Scope of A: protected fields are accessible by any class that extends the base class. The extending class can be but does not have to be in the same package as the base class.

Scope of B: package-scoped, or "default" variables, are only accessible by classes in the same package.

A is _not_ a subset of B
A is _not_ a superset of B
A is _not_ equal to B

(A union B) is any class in the same package or extending the class. (A intersection B) is just the classes within the same package that extend B.

So, the following assertion is true:

 (A union B) is not equal to (A intersection B)
Isn't (A union B) is not equal to (A intersection B)
Really the same as A not equal to B.
> Scope of A: protected fields are accessible by any class
> that extends the base class. The extending
> class can be but does not have to be in the same package
> as the base class.

They are also visible from all classes in the same package.

Hehe, that's true. The last option also makes no sense. Either A = B or A != B. I consider those both relations.
>They are also visible from all classes in the same package.

Wow, I never knew that, but I just verified it. In my opinion this is not how it should be, but this isn't something that's going to change.

In this case, however, it doesn't change the answer, as A still differs from B.
...but yes, A is also a superset of B
geeze, I sure wish you could revise comments. What a mess I've made :)
Since when has this become a homework help site? ;P
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to objects@idg

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer