-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
31 lines (26 loc) · 792 Bytes
/
Copy pathStudent.java
File metadata and controls
31 lines (26 loc) · 792 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
class Student {
String name;
int age;
// Default Constructor
public Student() {
this.name = "Default Name";
this.age = 18;
}
// Parameterized Constructor
public Student(String name, int age) {
this.name = name;
this.age = age;
}
// Method to display student details
public void display() {
System.out.println("Name: " + name + ", Age: " + age);
}
public static void main(String[] args) {
// Creating object using the default constructor
Student student1 = new Student();
student1.display();
// Creating object using the parameterized constructor
Student student2 = new Student("John Doe", 20);
student2.display();
}
}