-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevisionSolution.java
More file actions
38 lines (31 loc) · 893 Bytes
/
Copy pathRevisionSolution.java
File metadata and controls
38 lines (31 loc) · 893 Bytes
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
class Student {
private String name;
private int age;
Student(String name, int age) {
this.name = name;
this.age = age;
}
public String GetName() {
return name;
}
public int GetAge() {
return age;
}
// Override toString() method
@Override
public String toString() {
return "Name: " + name + ", Age: " + age;
}
}
public class RevisionSolution {
public static void main(String[] args) {
Student[] students = new Student[3];
students[0] = new Student("Vinay Kumar", 20);
students[1] = new Student("Anish Kumar", 23);
students[2] = new Student("Arjun Sahani", 23); // Fixed index 2
// students[3] remains uninitialized (you can add another student here)
for(Student student:students){
System.out.println(student);
}
}
}