This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about protected 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 "Doubt about protected" Watch "Doubt about protected" New topic
Author

Doubt about protected

Xiao Song
Greenhorn

Joined: Aug 29, 2006
Posts: 17


After compile, it said "i has protected access in p1.A" in line 15.
Why, B is subclass of A, and member i in A is protected. in my opinion, subclss can access protected member of baseclass.
[ November 21, 2006: Message edited by: Barry Gaunt ]

scjping.......
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

you are correct, subclass can all the protected memebers of superclass, but only through inheritance and not through object reference, If package of subclass is different from superclass.

This should work,


public class B extends p1.A
{
public void process(A a)
{
i = i*2;
}
....


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Doubt about protected
 
It's not a secret anymore!