Abstract class program
Write a java program to create an abstract class named Shape that contains two integers and an empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printAr
Abstract class program
JAVA videos
Write a java program to create an abstract class named Shape that contains two integers and an empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea( ) that prints the area of the given shape.
abstract class Shape
{
int a, b;
abstract void printArea();
}
class Rectangle extends Shape
{
public Rectangle(int x, int y)
{
a = x;
b = y;
}
public void printArea()
{
System.out.println("Rectangle Area => " + (a * b));
}
}
class Triangle extends Shape
{
public Triangle(int x, int y)
{
a = x;
b = y;
}
public void printArea()
{
System.out.println("Triangle Area => " + (0.5 * a * b));
}
}
class Circle extends Shape
{
public Circle(int x)
{
a = x;
}
public void printArea()
{
System.out.println("Circle Area => " + (3.14 * a * a));
}
}
public class Practical19{
public static void main(String[] args)
{
Rectangle R = new Rectangle(10,20);
Triangle T = new Triangle(5,10);
Circle C = new Circle(8);
R.printArea();
T.printArea();
C.printArea();
}
}
Interface program
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.