• 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

neeed help !!!!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic