• 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

reg overriding

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a super/sub class as below



the 1 line will call the sub class method but I want it should call only super class method with out creating object of super class........

Please any suggestions.....solution.....help:-)
[ November 20, 2008: Message edited by: Martijn Verburg ]
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the 1 line wiill call the sub class method but i want it shoud call only super class method with out creating object of super class........



It is *not* creating object of super class -- it is the sub class that is being created. Remember a sub class IS-A super class. It can be used where the super class is used.

And no, you can't decide that the sub class is no longer a sub class. The overridden version will be called because it IS-A sub class.

Henry
 
swapna hyderabad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is ::

super s=new sub();

s.dispaly();//1

This line 1 shoud call the super cls method only...means i want to be excute super cls method implementaion..is it possible or not?
 
Marshal
Posts: 79512
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call super.display() but only from inside a subclass object (ie not static).
You cannot write "super s"; that will always throw a compiler error because you have the keyword super out of its correct context.
 
swapna hyderabad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can call super.display() but only from inside a subclass object (ie not static).



thanks for reply.....
but i want only it shoud execute super cls method,i.e i dont want to excute sub class implementation at all......any solution?
 
Campbell Ritchie
Marshal
Posts: 79512
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only call the superclass implementation from inside the subclass. If you want the superclass implementation from outside that, you have to make sure your runtime type of the object is a superclass type. Two possible solutions I can think of:What you want to learn is object-oriented programming, not a particular language.
Using a superclass method which has been overridden in the object you are using breaches the customs of inheritance and polymorphism; it ceases to be true object-oriented programming.
 
swapna hyderabad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...Campbell ...you solved my problem........THANKS AGAIN
 
Campbell Ritchie
Marshal
Posts: 79512
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
reply
    Bookmark Topic Watch Topic
  • New Topic