Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
General <strong>Java</strong> Questions I<br />
Also note, that super.clone() always returns an Object of the type of the actual object,<br />
although the superclass doesn't know anything about that sub class. The reason is,<br />
that Object.clone() is a native method, which just allocates new memory for the new<br />
object and copies the bytes to that memory. Native code has it's own ways of finding<br />
out which type to return ;-)<br />
--<br />
Karl Schmidt<br />
I was just wondering about the usefulness of Interfaces...<br />
I was just wondering about the usefulness of Interfaces. I was under the impression<br />
that interfaces could be used to perform multiple inheritance. But an interface only<br />
declares a method - in a very abstract way.<br />
A class that implements an interface needs to define its own implementation of a<br />
certain method. What is the use of having an interface when nothing is being<br />
gained...?<br />
Answer: If two classes implements the same interface, you can get a reference to the<br />
interface instead of the effective class without bother what class are you managing.<br />
This is very useful in RMI (for example) or in any condition when you have to take an<br />
object without knowing exactly his class, but only the interface that it implement.<br />
For example:<br />
public void recurseList( List l )<br />
the generic List ensure that you can use every List for this method (ArrayList,<br />
AbstractList, Vector...), so your calling method can be:<br />
ArrayList l = new ArrayList(); or<br />
Vector l = new Vector();<br />
recurseList( l );<br />
Without any problem.<br />
by Davide Bianchi<br />
Q: I got a problem with an array/vector...<br />
I got a problem with an array/vector.<br />
my class contains a member:<br />
static Vector quad[][];<br />
....<br />
in my constructor I got:<br />
Vector quad[][] = new Vector[row][col];<br />
for (int i = 0; i < row; i++){<br />
for (int j = 0; j < col; j++){<br />
quad[i][j] = new Vector (0,1);<br />
}<br />
}<br />
file:///F|/350_t/350_tips/general_java-I.htm (14 of 31) [2002-02-27 21:18:17]