• 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

Can we use a derived class pointer to point to a base class method?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we use a derived class pointer to point to a base class method? I ve tried it. it is showing error if i used to point a base class method through a derived class object. But when i use static blocks alone in both the classes, the program is executing successfully. Whats the reason behind it?
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please post your code
and also your question is unclear
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

V Aravind wrote:Can we use a derived class pointer to point to a base class method? .....



What is this? Pointer in java?
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

V Aravind wrote:Can we use a derived class pointer to point to a base class method? I ve tried it. it is showing error if i used to point a base class method through a derived class object. But when i use static blocks alone in both the classes, the program is executing successfully. Whats the reason behind it?



if you are talking in java terms then their is no pointer.........

lets see




then you cannot cast the sub class object to a superclass because when a superclass object is created then it doesnot know anything about subclass so class cast excwption is thrown..........

for example for above code.......
//will give class cast exception because at runtime when super class object is created then it doesnot know anything about sub.

hope this helps you.............

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
V Aravind - your question is unclear, can you post some code?

just to elaborate on what phil sohar said (if this is what you are asking)



 
reply
    Bookmark Topic Watch Topic
  • New Topic