27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

General <strong>Java</strong> Questions III<br />

Receive our newsletter with new tips! Almost 6,000 subscribers (by June 2001) can not be<br />

wrong!<br />

They read our tips every week! To subscribe to The <strong>Java</strong> FAQ Daily send empty e-mail to:<br />

javafaq-tips-subscribe@topica.com or visit at:<br />

http://www.topica.com/lists/javafaq-tips/<br />

General <strong>Java</strong> Questions III<br />

Q: I propose that <strong>Java</strong> should allow multiple inheritance if...<br />

Everyone knows the potential problem with multiple inheritance is when you run into<br />

the problem of having two instances of a grand parent super class.<br />

For example:<br />

class A extends D {int i; }<br />

class B extends D {int i; }<br />

class C extends A,B {}<br />

Potentially, you could have two copies of D for each instance of C.<br />

However, I propose that <strong>Java</strong> should allow multiple inheritance if there are no<br />

instance variables associated with the abstracts that the base class is extending.<br />

abstract class A { public setX(); public setY(); public setAll() {setX (); setY(); }<br />

abstract class B { public setC(); public setD(); public setBoth()<br />

{setC(); setD(); }<br />

class C extends A,B {}<br />

Visit us here and you will find<br />

much more tips!<br />

You won't have two instances of some grandfather class, since A and B doesn't have<br />

instances variables.<br />

I hope the next versions of <strong>Java</strong> explores this issue.<br />

Answer: It does. They're called interfaces:<br />

file:///F|/350_t/350_tips/general_java-III.htm (1 of 9) [2002-02-27 21:18:30]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!