Professional Documents
Culture Documents
WEEK5
WEEK5
Objective: After the completion of the practice session, the student will be able
to implement OOP Third principle – Inheritance.
import java.util.*;
class Emp
{
int empid;
String empname;
Emp(int no)
{
empid = no;
}
Emp(int no , String name)
{
this(no);
empname = name;
}
}
Output:
b) Write a Java program that create an abstract base class Shape with
two members base and height, a member function for initialization
and a function to compute shapeArea(). Derive two specific classes
Triangle and Rectangle which override the function shapeArea().
Write a driver classes (main) to display the area of the triangle and
the rectangle.(Use super keyword).
double shapeArea()
{
return(base*hgt);
}
}
Output: