CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-USING ABSTRACT CLASS

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY


QUESTION:Write a Java Program to create an abstract class named Shape that contains two integers and an empty method named print Area(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method print Area () that prints the area of the given shape.


Program:


import java.util.Scanner;
abstract class Shape{
int A=10,B=5;
abstract void Area();
}

class Rectangle extends Shape{
void Area(){
System.out.println("Area of an rectangle (area=Length*width)"+A*B);
}
}
class Triangle extends Shape{
void Area(){
System.out.println("Area of an Triangle (area=0.5*height*base)"+0.5*A*B);
}
}

class Circle extends Shape{
void Area(){
System.out.println("Area of a circle is (a=3.14*a*a)"+3.14*A*A);
}
}


class Findarea{
public static void main(String args[]){
Shape obj=new Rectangle();
obj.Area();

Shape obj1=new Circle();
obj1.Area();

Shape obj2=new Triangle();
obj2.Area();
}
}
--------------------------------------------------------------------------------------------------------------------------
OUTPUT:

Area of an rectangle (area=Length*width)50                                                                                       
Area of a circle is (a=3.14*a*a)314.0                                                                                            

Area of an Triangle (area=0.5*height*base)25.0  

Comments

Post a Comment

Popular posts from this blog

CS8461- OPERATING SYSTEMS LABORATORY-Write C programs to simulate UNIX commands like cp, ls, grep, etc.

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-JAVA EMPLOYEE PROGRAM USING INHERITANCE CONCEPT FOR

CS8382-OBJECT ORIENTED PROGRAMMING LABORATORY-TO GERNERATE EMPLOYEE SALARY SLIP PROGRAM IN JAVA