-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStudentsExample.java
More file actions
32 lines (27 loc) · 894 Bytes
/
StudentsExample.java
File metadata and controls
32 lines (27 loc) · 894 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
public class StudentsExample {
// create a Student class
String name;
int rollNo;
String section;
// initialize attributes
StudentsExample(String name, int rollNo, String section){
this.name= name;
this.rollNo = rollNo;
this.section = section;
}
// print details
public void printDetails() {
System.out.print("Student Details: ");
System.out.println(this.name+ ", " + this.rollNo + ", " + section);
}
public static void main(String[] args) {
// create student objects
Students student1 = new Students("Robert", 1, "IX Blue");
Students student2 = new Students("Adam", 2, "IX Red");
Students student3 = new Students("Julie", 3, "IX Blue");
// print student details
student1.printDetails();
student2.printDetails();
student3.printDetails();
}
}