You are on page 1of 4

Experiment no :- 01

Title: To study Inheritance,Interfaces and implement the program.


Problem Statement: Create a class Teacher and derive Professor/Associate
Professor/Assistant Professor class from teacher class. Define appropriate
constructor for all the classes. Also define a method to display information of
Teacher. Make necessary assumptions required.
Theory:
Inheritance : The process by which one class acquires the properties(data members)
and functionalities(methods) of another class is called inheritance. It is the
mechanism in java by which one class is allowed to inherit the features(fields and
methods) of another class.
Super Class: The class whose features are inherited is known as superclass(or a base
class or a parent class).
Sub Class: The class that inherits the other class is known as subclass(or a derived
class,extended class, or child class). The subclass can add its own fields and methods
in addition tothe superclass fields and methods.
Syntax:
class derived-class extends base-class
{
//methods and fields
}
Types Of Inheritance :
1.Single Inheritance
2. Multilevel inheritance
3. Hierarchical inheritance
4. Multiple Inheritance
5. Hybrid inheritance
Hierarchical Inheritance: In Hierarchical Inheritance , One class serves as a
superclass for more than one subclass.

Algorithm:
1. Start the Program
2. Create a SuperClass Teacher
3. Declare the Display Method
4. Create three more classes(Professor/Associate Professor/Assistant Professor)
and Extend the Parent class and declare display method
5. Call the main method and create object
6. Display the object
7. Stop the Program
Program:
class Teacher
{
public void print_Teacher()
{
System.out.println("Ms. Rita Roy");
}
}
class Professor extends Teacher
{
public void print_Professor()
{
System.out.println("Ms. Suhasini Shukla");
}
}
class Associate_Professor extends Teacher
{
public void print_Associate_Professor()
{
System.out.println("Ms. Veena Jagtap");
}
}
class Assistant_Professor extends Teacher
{
public void print_Assistant_Professor()
{
System.out.println("Ms. Maya Singh");
}
}
public class EXP_1
{
public static void main(String[] args)
{
Teacher t = new Teacher();
t.print_Teacher();
Professor p = new Professor();
p.print_Professor();
Associate_Professor ap = new Associate_Professor();
ap.print_Associate_Professor();
Assistant_Professor asp = new Assistant_Professor();
asp.print_Assistant_Professor();
}
}

You might also like