• 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

Overriding protected method

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Its written in K&B book,page number 102:

A subclass in a different pacakage can override only those non-final methods marked public or protected.



But when I write the code:



Getting compile error at commented line.
Can anybody explain why I am getting error.
Thnks.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because you defined your Base Typ "Vehical" at this line

Vehical car = new Car();

The compiler is looking for the start method in the Vehical class (at runtime the start method in the car class will called), but because you marked it protected you have no access to the start method.
[ October 24, 2007: Message edited by: Dzu-I Kou ]
 
Saurabh Verma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Dzu-I Kou Thnks for the reply.
As I am overriding start() method.Could called that method through the refernce of super class.
 
Raphael Kou
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope I got your question.

In the Car class, you cannot access Vehical methods through a Vehical Object (except the method is public). You can use the super keyword to access Vehicals methods (if override) or just direct.
[ October 24, 2007: Message edited by: Dzu-I Kou ]
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic