0% found this document useful (0 votes)
20 views5 pages

Multilevel Inheritance Java Program

The document contains two Java programs demonstrating inheritance concepts. The first program implements multilevel inheritance with classes Person, Employee, and Manager, showcasing employee details. The second program illustrates single inheritance with classes Room and RoomVolume, calculating area and volume of a room.

Uploaded by

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

Multilevel Inheritance Java Program

The document contains two Java programs demonstrating inheritance concepts. The first program implements multilevel inheritance with classes Person, Employee, and Manager, showcasing employee details. The second program illustrates single inheritance with classes Room and RoomVolume, calculating area and volume of a room.

Uploaded by

pravindsawate
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name:-Sangharsh parvind Sawate

Class:-co4k(B)
Roll no:-64
Sub:-JPR(314317)

Practical no:-8
[Link] a program to implement Multilevel inheritance
Code:-
class Person
{
String name;
int age;
public Person(String name, int age)
{
[Link] = name;
[Link] = age;
}
public void displayPerson()
{
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}
class Employee extends Person
{
int empId;
double salary;
public Employee(String name, int age, int empId, double salary)
{
super(name, age);
[Link] = empId;
[Link] = salary;
}
public void displayEmployee()
{
displayPerson();
[Link]("Employee ID: " + empId);
[Link]("Salary: $" + salary);
}
}
class Manager extends Employee
{
String department;
public Manager(String name, int age, int empId, double salary,
String department)
{
super(name, age, empId, salary);
[Link] = department;
}
public void displayManager()
{
displayEmployee();
[Link]("Department: " + department);
}
}
public class student
{
public static void main(String[] args)
{
Manager mgr = new Manager("Sangharsh", 18, 101, 75000.50,
"Computer science");
[Link]("Manager Details:");
[Link]();
}
}
Output:-
[Link] a program to calulate he room area and volume to illustrate the
concept of single inheritance.
Code:-
public class Room
{
double length, breadth;
public Room(double length, double breadth)
{
[Link] = length;
[Link] = breadth;
}
public double calculateArea()
{
return length * breadth;
}
}
class RoomVolume extends Room
{
double height;
public RoomVolume(double length, double breadth, double height)
{
super(length, breadth);
[Link] = height;
}
public double calculateVolume()
{
return length * breadth * height;
}
}
public class RoomCalculations
{
public static void main(String[] args)
{
RoomVolume room = new RoomVolume(10, 12, 8);
[Link]("Room Area: " + [Link]() + " sq. units");
[Link]("Room Volume: " + [Link]() + " cubic
units");
}
}
Output:-

You might also like