67 lines
1.5 KiB
Java
67 lines
1.5 KiB
Java
class Student {
|
|
|
|
int regNo;
|
|
String name;
|
|
int age;
|
|
|
|
public Student(int regNo, String name, int age) {
|
|
this.regNo = regNo;
|
|
this.name = name;
|
|
this.age = age;
|
|
}
|
|
|
|
public void displayDetails() {
|
|
System.out.println(
|
|
"Reg No: " + regNo + ", Name: " + name + ", Age: " + age
|
|
);
|
|
}
|
|
}
|
|
|
|
class UG extends Student {
|
|
|
|
int semester;
|
|
double fees;
|
|
|
|
public UG(int regNo, String name, int age, int semester, double fees) {
|
|
super(regNo, name, age);
|
|
this.semester = semester;
|
|
this.fees = fees;
|
|
}
|
|
|
|
public void displayDetails() {
|
|
super.displayDetails();
|
|
System.out.println("Semester: " + semester + ", Fees: " + fees);
|
|
}
|
|
}
|
|
|
|
class PG extends Student {
|
|
|
|
int semester;
|
|
double fees;
|
|
|
|
public PG(int regNo, String name, int age, int semester, double fees) {
|
|
super(regNo, name, age);
|
|
this.semester = semester;
|
|
this.fees = fees;
|
|
}
|
|
|
|
public void displayDetails() {
|
|
super.displayDetails();
|
|
System.out.println("Semester: " + semester + ", Fees: " + fees);
|
|
}
|
|
}
|
|
|
|
public class StudentProgram {
|
|
|
|
public static void main(String[] args) {
|
|
UG ugStudent = new UG(230901010, "Saarthak Singhal", 20, 3, 500000.0);
|
|
PG pgStudent = new PG(230920020, "Aarav Chirag Shah", 25, 2, 350000.0);
|
|
|
|
System.out.println("UG Student Details:");
|
|
ugStudent.displayDetails();
|
|
|
|
System.out.println("\nPG Student Details:");
|
|
pgStudent.displayDetails();
|
|
}
|
|
}
|