Inheritance Abstract class program
Write a java program that implements educational hierarchy using inheritance. In this program abstract class is used. An abstract class can't be instantiated(you can't create an object of these classes). An abstract class is a class which has at least one abstract method. An abstract method can't ha
Abstract class program
JAVA videos
Write a java program that implements educational hierarchy using inheritance.
In this program abstract class is used. An abstract class can't be instantiated(you can't create an object of these classes). An abstract class is a class which has at least one abstract method. An abstract method can't have a method body, it has to be implemented by the class which is inheriting this abstract class.

import java.util.Scanner;
abstract class Office
{
int empNo;
String empName;
int salary;
abstract void getData();
}
class Teaching extends Office
{
String designation;
void setData()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Employ number => ");
empNo = sc.nextInt();
System.out.print("Enter Employ name => ");
empName = sc.next();
System.out.print("Enter salary => ");
salary = sc.nextInt();
System.out.print("Enter designation => ");
designation = sc.next();
}
void getData()
{
System.out.println("Employ name => " + empName + "\t\tEmploy number => " + empNo);
System.out.println("Salary => " + salary + "\t\tDesignation => " + designation);
}
}
class Non_teaching extends Office
{
String designation;
void setData()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Employ number => ");
empNo = sc.nextInt();
System.out.print("Enter Employ name => ");
empName = sc.next();
System.out.print("Enter salary => ");
salary = sc.nextInt();
System.out.print("Enter designation => ");
designation = sc.next();
}
void getData()
{
System.out.println("Employ name => " + empName + "\t\tEmploy number => " + empNo);
System.out.println("Salary => " + salary + "\t\tDesignation => " + designation);
}
}
public class Practical14
{
public static void main(String[] args)
{
Teaching t1 = new Teaching();
Non_teaching nt1 = new Non_teaching();
System.out.println("Data about Teaching class => \n");
t1.setData();
t1.getData();
System.out.println("\n\nData about Non teaching class => \n");
nt1.setData();
nt1.getData();
}
}
Inheritance of interface
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.