M
Marmagya
Hello,
I am trying to find out if I can populate a Vector in java with more
than data types:
-----------
import java.util.*;
import java.lang.*;
public class DiffVector {
class A {
String a = null;
A(){
a = new String("java");
}
}
void createVector() {
Vector v = new Vector();
v.addElement(new Integer(1));
DiffVector var = new DiffVector();
DiffVector.A a = new DiffVector.A();
v.addElement(a);
System.out.println("the vector is : " + v);
return;
}
public static void main(String args[]) {
DiffVector var1 = new DiffVector();
var1.createVector();
return;
}
}
-----------
The output of this is : "the vector is : [1, DiffVector$A@bd0108]"
I am expecting that either this program should not compile since I am
inserting data of different types, or it should display the second
element as "java".
Can someone tell me why I am getting this output?
Regards
Vineet
I am trying to find out if I can populate a Vector in java with more
than data types:
-----------
import java.util.*;
import java.lang.*;
public class DiffVector {
class A {
String a = null;
A(){
a = new String("java");
}
}
void createVector() {
Vector v = new Vector();
v.addElement(new Integer(1));
DiffVector var = new DiffVector();
DiffVector.A a = new DiffVector.A();
v.addElement(a);
System.out.println("the vector is : " + v);
return;
}
public static void main(String args[]) {
DiffVector var1 = new DiffVector();
var1.createVector();
return;
}
}
-----------
The output of this is : "the vector is : [1, DiffVector$A@bd0108]"
I am expecting that either this program should not compile since I am
inserting data of different types, or it should display the second
element as "java".
Can someone tell me why I am getting this output?
Regards
Vineet