• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance question

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good post that cleared my doubts. thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic