General Java Questions III
Visit us here and you will find
much more tips!
Receive our newsletter with new tips! Almost 6,000 subscribers (by June 2001) can not be
wrong!
They read our tips every week!
To subscribe to The Java FAQ Daily send empty e mail to:
javafaq tips subscribe@topica.com
or visit at:
http://www.topica.com/lists/javafaq tips/
General Java Questions III
Q: I propose that Java should allow multiple inheritance if...
Everyone knows the potential problem with multiple inheritance is when you run into
the problem of having two instances of a grand parent super class.
For example:
class A extends D {int i; }
class B extends D {int i; }
class C extends A,B {}
Potentially, you could have two copies of D for each instance of C.
However, I propose that Java should allow multiple inheritance if there are no
instance variables associated with the abstracts that the base class is extending.
abstract class A { public setX(); public setY(); public setAll() {setX (); setY(); }
abstract class B { public setC(); public setD(); public setBoth()
{setC(); setD(); }
class C extends A,B {}
You won t have two instances of some grandfather class, since A and B doesn t have
instances variables.
I hope the next versions of Java explores this issue.
Answer: It does. They re called interfaces:
interface A { public void setX(); public void setY(); public void setAll(); }
interface B { public void setC(); public void setD(); public void setBoth(); }
interface C extends A,B {};
public abstract class D implements C {
file:///F|/a_jsite/350_tips/general_java III.htm (1 of 9) [2001 07 08 11:24:53]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved