This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes neeed help !!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "neeed help !!!!" Watch "neeed help !!!!" New topic

neeed help !!!!

Ganesh kumar

Joined: Sep 06, 2005
Posts: 5
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

Joined: Feb 24, 2004
Posts: 236
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.

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 ]

Paul M. Santa Maria, SCJP
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: neeed help !!!!
It's not a secret anymore!