-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjStore.java
More file actions
48 lines (48 loc) · 1.07 KB
/
Copy pathObjStore.java
File metadata and controls
48 lines (48 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Storing the Object in vector
*/
import java.util.*;
class Employee
{
private int id;
private String name;
private int salary;
Employee(int id, String name, int salary)
{
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
public int getSalary()
{
return salary;
}
}
public class ObjStore
{
public static void main(String x[])
{
Vector vt = new Vector();
Employee e1 = new Employee(1,"Aniket",4000); // creating objects of the Employee class
Employee e2 = new Employee(2,"yd",5000);
Employee e3 = new Employee(3,"gb",6000);
vt.add(e1); // adding this objects into vector class
vt.add(e2);
vt.add(e3);
Iterator i = vt.iterator(); // iterating one by one
while(i.hasNext()) // checking the next object is present in array or not
{
Object obj = i.next(); // accessing the object
Employee e = (Employee)obj; // converting this object into class reference
System.out.println(e.getId()+"\t"+e.getName()+"\t"+e.getSalary()); // printing each values of object
}
}
}