aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Protected in subclasses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Protected in subclasses" Watch "Protected in subclasses" New topic
Author

Protected in subclasses

Imad Aydarooos
Ranch Hand

Joined: Nov 02, 2010
Posts: 87
My question is written in the code below


/////////////////////////////////////////

But after checking i figured out the following:
1- Gamma object IS A Beta, so it can access the protected inherted member x.
2- Beta object IS NOT A Gamma, but Gamma has A Beta, in this case protected members are not visible to the composed object which is Beta object.

please elaborate on this and correct me if I'm wrong

Regards


love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

look for section 6.6.7 here

and to confuse you , what happened if Alpha's protected x would have been marked as static? remember protected makes sense if it is defined before instance variable/method.
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier


Life is either daring something or nothing - Helen Keller
Imad Aydarooos
Ranch Hand

Joined: Nov 02, 2010
Posts: 87
Bharath Raja wrote:Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier


This is not true Bharath Raja , the above code will compile and output:
10
10
0
10
10
which is a proof that your statment is not true
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
Imad Aydarooos wrote:
Bharath Raja wrote:Please remember, protected modifier can have accessible within the package only. If you want to use that variable then leave it as default modifier


This is not true

oops.. sorry for that... default is only strict package level access
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected in subclasses
 
Similar Threads
Please help me to get Java Certification
Accessing inherited protected instance variable question
can't access finalize() method !!!
Doubt with a code
Why doesn't polymorphism determine the output in this case?