• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

multiple inheritance in java

 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How do I achieve muliple inheritance in java even
though java language provides no direct way for this.
Thanks
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read up on interfaces... this is java's way around multiple inheritance.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every few months someone asks this question, and the answer is usually another question. Which facets of what is lumped together in (say) C++ and called "multiple inheritance" do you actually need?
If you need "polymorphism", where a class is treated as if it is an object of some base class, use an interface - a class can implement as many interfaces as you like.
If you need to share the internal data from several classes, include instances of those classes as member variables and delegate any methods you need to the appropriate members.
Above all, first try and solve your problem without multiple inheritance. The great majority of problems have a solution using plain single inheritance, and where you do need something of it, you can use the sort of techniques I describe above.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic