aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inheritance question 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 "inheritance question" Watch "inheritance question" New topic
Author

inheritance question

roy john
Greenhorn

Joined: Jun 03, 2003
Posts: 4
i know that a protected instance method can be called from within any subclass. so i don't understand why the following code can't compile. shouldn't clone (a protected method ) of the object class be able to be called from the subclass?
public class Sub extends Object {
public static void main(String [] args) {
Object x = new Object();
// compiler complains that clone is protected
x.clone();
}
}
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Roy
Welcome to javaranch. The method is protected and hence is only available to classes in the same package or subclasses. But subclasses have only the inherited method that is they can use clone as in the following code but can not access it the way you are trying to access it it. There is a very good descision on this. You will find it here.


[ June 03, 2003: Message edited by: Anupam Sinha ]
Brian Joseph
Ranch Hand

Joined: May 16, 2003
Posts: 160
Anupam, good reference there. That was a good read! I didn't originate this post, but thanks!
[ June 03, 2003: Message edited by: Brian Joseph ]
roy john
Greenhorn

Joined: Jun 03, 2003
Posts: 4
good post that cleared my doubts. thanks!
 
jQuery in Action, 2nd edition
 
subject: inheritance question