Inheritance Lab Pgm
Inheritance Lab Pgm
// Use the @Override annotation to indicate that this method overrides a method in the superclass
@Override
// Define the getArea method that returns a double
public double getArea()
{
Output:
2. Write a Java program to create a class called Employee with methods called work() and getSalary()
1
public class Employee
{
private int salary;
public Employee(int salary)
{
this.salary = salary;
}
Output:
working as an employee!
Employee salary: 40000
Managing employees
Manager salary: 70000
Output
This is a Vehicle
This is a Vehicle
This is a Car
This is a Motorcycle
// class 1
// To store dimensions of a cuboid used to store length, breadth and height of a cuboid
class Cuboid
{
public double length;
public double breadth;
public double height;
}
// Class 2
//To store dimensions of a sphere
class Sphere
{
// Class 3
// This class helps to calculate the volume of geometric objects
class Application {
// Iteratively calculating the volume of each Cuboid and adding it to the total volume