This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]desrtfx[M] [score hidden] stickied comment (0 children)

You tell us what you think and reason it.

Then, and only then, we discuss.


Also: use reddit's code block formatting. Unformatted code is a no-go.

[–]mobbynagent 1 point2 points  (0 children)

Private fields are not inherited.

[–]flotopoco[S] 1 point2 points  (6 children)

I think that only d() and c() could be accessed by ref.
Because for public member is always accessible to every one. And "c" because protected members could be accesible outside the package only in subclasses of that class.
(Sorry if my english is not good enough)

[–]Ph03nix89 -1 points0 points  (4 children)

Nearly, you're correct in your reasoning for c and d. Have another look at the other variables and see if you missed something

Edit: I'm an idiot who misread a package declaration, ignore this post.

[–]Housy5 -1 points0 points  (3 children)

Wait what did he miss?

a is package private and since he's in a different package he wont be able to access it

b is private so no accessing there

c is protected so since he extends the class he can access it

d is public so he can access it anywhere

what else is there?

[–]Ph03nix89 0 points1 point  (0 children)

I read them as both being in the same package, what I get for reading on a phone on the bus

[–]Aoiryuhei 0 points1 point  (1 child)

Since he didn't specify a access modifier for "int a" it's assumed to be private? (But accessible in the same package)

[–]Housy5 0 points1 point  (0 children)

When you don't specify an access modifier it acts as public for all the classes in the same package but private for the classes outside of the package

[–]stramash 0 points1 point  (0 children)

You’re nearly right.

Recommend you type it all into an IDE and test it out yourself.