Add OOP/Java/Lab/Week6/Student/StudentProgram.java
This commit is contained in:
parent
d12bfe4593
commit
2a97c1f104
66
OOP/Java/Lab/Week6/Student/StudentProgram.java
Normal file
66
OOP/Java/Lab/Week6/Student/StudentProgram.java
Normal file
@ -0,0 +1,66 @@
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user