• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Multiple Inheritence in JAVA

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,
Java does not allow multiple inheritance as such, but for example
public class B extends A,implements C,implements D
{
.......
}
firstly is this allowed and if so is this a way of getting around the lack of multiple inheritance.
I personnaly do not like multiple inheritance because it can lead ot all kind of comlications.
Any suggestions or ideas welcome
Jawahar
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close... it's actually:
public class B extends A implements C,D
{
.......
}
Yes, this is the way around multiple inheritance. We can inherit multiple interfaces. Since interfaces have no implemetation, this gets around the problems created by multiple inheritance.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned by Thomas, you are inheriting multiple interfaces and providing the implemention for those interfaces. While in the case of "Real" multiple inheritance in a language such as C++ you are actually inheriting the implementation.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe java does not allow multiple inheritence due to the complications you mention.
You correct in pursuing multiple inheritence via Interfaces
public class B extends A implements C, D
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java does not implement multiple inhieritence. Interestingly enough, Bjarne Stroustrup, the author of "The C++ Language" and inventer of C++ once said that if he had to do it over again he would not have put multiple inhieritence into C++.
Jawahar, if you're coming from a C++ background then it may help you to think of implementing an interface as being the same as inhieriting a pure abstract class in C++. In a pure abstract class only the function headers are described, but there is no functionality. That, in essence, is the same as implementing an interface.
 
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
Is there a specific, and genuinely useful, algorithm you are trying to implement that requires you to actually be able to know and/or manipulate the memory address of an item?
Aside from academic exercises, I've been pondering but can't really come up with anything I'd like to do that would require this type of internal access.
What did you have in mind?
bear
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!