Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

neeed help !!!!

 
Ganesh kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can this be donw???

Given classes A, B, and C, where B extends A, and C extends B, and where all classes implement the instance method void doIt(). How can the doIt() method in A be called from an instance method in C?
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint:
1. Write a program that has classes A, B, and C as you described them.

2. Give each a "doIt()" method that just says 'System.out.println ("A::doIt()");'

3. Create a "main()". Have it create any one class (it doesn't matter which).

Have your "main()" call that object's (currently one-line) "do_it()".

Verify that it works.

4. Now that you've got a working program to play with, see if you
can think of a solution to the actual problem.

Hint:
There are actually *several* different solutions. Some good, others
not so good.

The trick is to start *somewhere*.

Try steps 1) through 4), and see how far you get!

Keep us posted .. PSM
[ September 18, 2005: Message edited by: Paul Santa Maria ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul's post notwithstanding, the answer is "you can't, unless class B helps you out." Java is deliberately designed to make what you describe impossible, unless class B provides a "backdoor" so that A's "doIt" can be called independently of the override.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic