File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "neeed help !!!!" Watch "neeed help !!!!" New topic
Author

neeed help !!!!

Ganesh kumar
Greenhorn

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
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 ]

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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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: http://aspose.com/file-tools
 
subject: neeed help !!!!