Professional Documents
Culture Documents
Aaron
Aaron
Aaron
INHERITANCE
AIM: Implementation of Inheritance – how inheritance is handled using java keywords: extends
and implements.
PROGRAM
Create a super class Person. Declare the appropriate member variables and member methods.
create two derived classes Student and Faculty.
In class Person,
Write 1. a method to get the name of the person, Age of the person, Department of the person.
In student class,
Write 1.a method to get register number , the marks for student.( m1,m2,m3) .
It should call the parent class method to get name of the student, age of the student and
Department of the student
3. a method to display the name of the student, Age, department, register number, marks , total
marks and average in table format.
In Faculty Class,
Write 1. A method to get the faculty ID, Basic salary, HRA, DA, PF. .
It should call the parent class method to get name of the student, age of the student and
Department of the Faculty member.
SOURCE CODE
import java.util.Scanner;
class Person
{
String name;
int age;
String Dept_name;
void read()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the name");
name =sc.next();
System.out.println("Enter the age");
age=sc.nextInt();
System.out.println("Enter the Deptarment name");
Dept_name= sc.next();
}
void Search_id(){
int Search_id;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the Reg_no: ");
Search_id =sc.nextInt();
if(Search_id==reg_no){
System.out.println("Name | | "+name);
System.out.println("Age | | "+age);
System.out.println("dept | |"+Dept_name);
System.out.println("Reg | |"+reg_no);
System.out.println("mark1 | |"+m1);
System.out.println("mark2 | |"+m2);
System.out.println("mark3 | |"+m3);
System.out.println("total | |"+total);
System.out.println("averg | |"+avg);
}
else
void read()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the name");
name =sc.next();
System.out.println("Enter the age");
age=sc.nextInt();
System.out.println("Enter the Deptarment name");
Dept_name= sc.next();
System.out.println("Enter the faculty id");
faculty_ID=sc.nextInt();
System.out.println("Enter the Basic Salary");
Basic_salary =sc.nextInt();
System.out.println("Enter the HRA");
HRA= sc.nextInt();
System.out.println("Enter the DA");
DA= sc.nextInt();
System.out.println("Enter the FA");
FA= sc.nextInt();
}
System.out.println("age |"+age);
System.out.println("Dept| "+Dept_name);
System.out.println("fac |"+faculty_ID);
System.out.println("BS |"+Basic_salary);
System.out.println("HRA |"+HRA);
System.out.println("DA |"+DA);
System.out.println("FA |"+FA);
System.out.println("total |"+salary);
}
void Search_fid(){
int Search_fid;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the Faculty_id: ");
Search_fid =sc.nextInt();
if(Search_fid==faculty_ID){
System.out.println("faculty id | | "+faculty_ID);
System.out.println("Basic salary | | "+Basic_salary);
}
else
System.out.println("Invalid faculty id");
}
public class Main {
}
else
if(choice == 2){
f.read();
f.Tsalary();
f.display();
f.Search_fid();
}
else
System.out.println("Invalid choice");
OUTPUT