Inhertice Java ChiranjeebLAB
Inhertice Java ChiranjeebLAB
Date: .....................................
class Shape {
// Empty constructor
Shape() {
}
double area() {
return 0.0;
}
}
class Circle extends Shape {
private double radius;
Circle(double radius) {
this.radius = radius;
}
@Override
double area() {
return Math.PI * radius * radius;
}
}
class Rectangle extends Shape {
private double length;
private double width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
@Override
double area() {
return length * width;
}
}
public class Main {
public static void main(String[] args) {
// Create instances of Circle and Rectangle
Circle circle = new Circle(5);
Rectangle rectangle = new Rectangle(4, 6);
// Print areas
System.out.println("Area of Circle: " + circle.area());
System.out.println("Area of Rectangle: " + rectangle.area());
}
}
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50