General Java Questions I
in my constructor I got:
Vector quad[][] = new Vector[row][col];
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
quad[i][j] = new Vector (0,1);
}
}
// row and col are int between (10..50) it s a big I know, but that
might not be the problem
My PROBLEM (and I don t know what to do, really), I can t access quad[x][y] outside
of the constructor!!!! Within the constructor I ve got full access on quad[x][x]. Java
(1.2) returns a NullPointerException on any method except within the constructor!!!
What s my fault!???
Answer: I guess you shouldn t write Vector here:
Vector quad[][] = new Vector[row][col];
so, the correct variant may be:
quad[][] = new Vector[row][col];
I guess You just overridden your static variable with one defined in your constructor:
Vector quad[][].
Thus, you re initializing NOT your class scope static variable but your
constructor scope quad. It s not reachable outside the constructor. And as for static
quad, it has never been initialized! And a first reference to it causes
NullPointerException. I guess. I hope I m right :)
Xao Rom
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.
file:///F|/a_jsite/350_tips/general_java I.htm (16 of 33) [2001 07 08 11:24:51]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved