0% found this document useful (0 votes)
15 views4 pages

Program 4

Uploaded by

prathibhar070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Program 4

Uploaded by

prathibhar070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

OOP with Java Lab /21CSL35

PROGRAM :4

4. Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class
by writing three subclasses namely Teaching (domain, publications), Technical (skills), and
Contract (period). Write a Java program to read and display at least 3 staff objects of all three
categories.

Aim: Demonstrate the core object-oriented concept of Inheritance, polymorphism

PROGRAM:

import java.util.Scanner;
class Staff
{
String staffId;
String name;
long phone;
float salary;
public void accept()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Staff Id: ");
staffId = scanner.next();
System.out.print("Enter Name: ");
name = scanner.next();
System.out.print("Enter Phone: ");
phone = scanner.nextLong();
System.out.print("Enter Salary: ");
salary = scanner.nextFloat();

}
public void display()
{
System.out.println("Staff Id: " + staffId);
System.out.println("Name: " + name);
System.out.println("Phone: " + phone);
System.out.println("Salary: " + salary);
}
}
class Teaching extends Staff
{
String domain;
int n;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Domain: ");
domain = scanner.next();
System.out.print("Enter Number of Publications: ");
Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23
OOP with Java Lab /21CSL35

n = scanner.nextInt();
System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Domain: " + domain);
System.out.println("Publications:"+n);
System.out.println("\n");
}
}
class Technical extends Staff
{
String skill;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter technical Skills: ");
skill = scanner.nextLine();
System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Technical Skills: " + skill);
System.out.println("\n");
}

}
class Contract extends Staff
{
int period;
public void accept()
{
super.accept();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Period: ");
period = scanner.nextInt();
System.out.println("\n");
}
public void display()
{
super.display();
System.out.println("Contract Period: " + period);
}
}
class Four
{
public static void main(String[] args)
{

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23


OOP with Java Lab /21CSL35

Teaching teaching = new Teaching();


System.out.println("Enter the details of Teaching Staff");
teaching.accept();

Technical technical = new Technical();


System.out.println("Enter the details of Technical Staff");
technical.accept();

Contract contract = new Contract();


System.out.println("Enter the details of Contract Staff");
contract.accept();

System.out.println("The details of Teaching Staff");


teaching.display();
System.out.println("The details of Technical Staff");
technical.display();
System.out.println("The details of Contract Staff");
contract.display();
}
}

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23


OOP with Java Lab /21CSL35

OUTPUT :

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23

You might also like