neeed help !!!!
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
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?
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
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
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
| a wee bit from the empire The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











