import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n;
Scanner in = new Scanner(System.in);
System.out.println("Enter number of student: ");
n=in.nextInt();
//arrays
Student [] s=new Student[n];
System.out.println("Enter the details of the "+n+" students:");
for(int i=0;i<n;i++){
s[i].getData();
}
System.out.println("The details of the "+n+" students are:");
for(int i=0;i<n;i++){
s[i].displayData();
}
Employee e1=new Employee();
e1.getData();
e1.displayData();
}
}
class Person{
protected String name;
protected int age;
protected String address;
}
//inheritance
class Student extends Person{
private int reg_no;
private String course;
private double fee_balance;
Scanner in=new Scanner(System.in);
public Student(int r){
reg_no=r;
}
public Student(){
}
public void getData(){
System.out.println("Enter name: ");
name=in.next();
System.out.println("Enter age: ");
age=in.nextInt();
System.out.println("Enter address: ");
address=in.next();
System.out.println("Enter reg number: ");
reg_no=in.nextInt();
System.out.println("Enter course: ");
course=in.next();
System.out.println("Enter fee balance");
fee_balance=in.nextDouble();
}
public void displayData(){
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Address: "+address);
System.out.println("Reg number: "+reg_no);
System.out.println("Course: "+course);
System.out.println("Fee balance: "+fee_balance);
}
}
//inheritance
class Employee extends Person{
private int emp_no;
private String emp_category;
private double salary;
Scanner in=new Scanner(System.in);
public void getData(){
System.out.println("Enter name: ");
name=in.next();
System.out.println("Enter age: ");
age=in.nextInt();
System.out.println("Enter address: ");
address=in.next();
System.out.println("Enter Employee number: ");
emp_no=in.nextInt();
System.out.println("Enter category: ");
emp_category=in.next();
System.out.println("Enter salary");
salary=in.nextDouble();
}
public void displayData(){
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Address: "+address);
System.out.println("Employee number: "+emp_no);
System.out.println("Category: "+emp_category);
System.out.println("Salary: "+salary);
}
}
Comments
Leave a comment