Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.*;
- import java.util.Scanner;
- class College {
- private String collegeName;
- public College() {
- collegeName = "Default College";
- }
- public College(String name) {
- collegeName = name;
- }
- public String getCollegeName() {
- return collegeName;
- }
- public void setCollegeName(String name) {
- collegeName = name;
- }
- }
- class Department extends College {
- private String departmentName;
- public Department() {
- departmentName = "Default Department";
- }
- public Department(String collegeName, String departmentName) {
- super(collegeName);
- this.departmentName = departmentName;
- }
- public String getDepartmentName() {
- return departmentName;
- }
- public void setDepartmentName(String name) {
- departmentName = name;
- }
- }
- class Student extends Department {
- private String studentName;
- private int studentID;
- public Student() {
- studentName = "Default Student";
- studentID = 0;
- }
- public Student(String collegeName, String departmentName, String studentName, int studentID) {
- super(collegeName, departmentName);
- this.studentName = studentName;
- this.studentID = studentID;
- }
- public String getStudentName() {
- return studentName;
- }
- public void setStudentName(String name) {
- studentName = name;
- }
- public int getStudentID() {
- return studentID;
- }
- public void setStudentID(int id) {
- studentID = id;
- }
- }
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter college name: ");
- String collegeName = scanner.nextLine();
- System.out.print("Enter department name: ");
- String departmentName = scanner.nextLine();
- System.out.print("Enter student name: ");
- String studentName = scanner.nextLine();
- System.out.print("Enter student ID: ");
- int studentID = scanner.nextInt();
- Student student = new Student(collegeName, departmentName, studentName, studentID);
- System.out.println("\n\n------------------------------------------------------");
- System.out.println("\nCollege Name: " + student.getCollegeName());
- System.out.println("Department Name: " + student.getDepartmentName());
- System.out.println("Student Name: " + student.getStudentName());
- System.out.println("Student ID: " + student.getStudentID());
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement