-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayOfObjects.java
46 lines (33 loc) · 999 Bytes
/
ArrayOfObjects.java
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
class Students
{
int rollno;
String name;
int marks;
}
public class ArrayOfObjects{
public static void main(String args[]){
Students s1 = new Students();
s1.rollno = 1;
s1.name = "sakshi";
s1.marks = 99;
Students s2 = new Students();
s2.rollno = 2;
s2.name = "sakshi";
s2.marks = 99;
Students s3 = new Students();
s3.rollno = 3;
s3.name = "sakshi";
s3.marks = 99;
// array of students
Students student[] = new Students[3];
// in this line we are not creating student object ,
// we are creating an array which can hold student refrences ,
//we have to mannuly create the objects ans assign to an array
student[0] = s1;
student[1] =s2;
student[2] = s3;
for(int i=0; i<student.length; i++){
System.out.println(student[i].name + " : " + student[i].marks);
}
}
}