Hello friends ,
I have a problm accessing my objects in vectors
what i am trying to do is store objects ( of a class defined by me) in a vector.
I have two classes VectorHandler and Emp_database.
In VectorHandler, I have a vector (Vector vect) which stores objects of Emp_database passed from the main() func.
In Emp_database , I have a string (name) which stores name of an employee.
I can pass an object from main() like:
import java.lang.*;
import java.io.*;
import java.util.*;
class ED{ //class object
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String name = new String();
void add(){
try{
System.out.println("Enter name : ");
name = in.readLine();
}
catch(IOException e){System.out.println("Error!");}
}
void display(){
System.out.println("You enterd : " + name);
}
}
class VectHandler extends ED{ //extends ED
Vector vect;
void add_vect(ED e){
add(); //will first store the data
vect = new Vector();
vect.addElement(e);
System.out.println("obj added!");
}
void disp_vect(){
//ED e = new ED();
//e = (e)vect.elementAt(0);
System.out.println(vect); //displays [ED@923e30]
}
}
class test2_ED_vect{
public static void main(String args[]) {
ED rec = new ED();
VectHandler v = new VectHandler();
v.add_vect(rec);
v.disp_vect(); //displays [ED@923e30]
}
}
What i want to do is display the name of the employee in the vector class