• 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

extending classes

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why couldn't I extend two or more clsses at the same time
(eg:Class1 extends Class2,Class3) if we could do the same thing
in c++.
Is this has something to do with pointers or else
just to avoid confusion with the calling methods of same name
(if same name for different methods in both super classes) or else something different?
jyothi abraham
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jyothi,
Java does not allow mutiple inheritance but it does give you counter solution by providing intefaces,which you can implement as many as you want in a class.
Thanks.
 
jyothi abraham
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But can you give that answer in detail to clarify my simple doubts that I raised,
Thank you,
JYOTHI ABRAHAM
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the books that I have read, all of them state that the biggest problem with multiple inheritance like C++ has is because of what you mentioned, if the multiple classes have the same method name, how do you know which one you are calling? I don't know C++, so again this is from what I have read.
An example that worked well for me is let's say you have two classes, Airplane and Boat. Each one has a direction() method. Airplanes can move in x, y, and z directions, Boats can move in x and y directions. Now let's say you have a class called FloatPlane (a plane that can land and take off on water). This class inherits from Airplane and Boat. Which implementation of direction() is going to be used? If you have a class that inherits from a whole bunch of other classes, and possibly each one of those classes has multiple inheritance, I can imagine this would be a logistical nightmare.
Jason
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In response to what Jason said, I think not allowing multiple inheiritance might be one of the things that makes Java so easy to learn compared to C++.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic