0% found this document useful (0 votes)
18 views1 page

Java Program for Area of Square and Cube

Uploaded by

anngodu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Java Program for Area of Square and Cube

Uploaded by

anngodu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

Scanner;
abstract class Shape{
abstract void area();
}
class Square extends Shape{
void area(){
[Link]("Enter the side of the square in centimeter");
Scanner scan=new Scanner([Link]);
int side=[Link]();
[Link]("The area of the square is: "+(side*side)+" square
centimeter");
}
}
class Cube extends Shape{
void area(){
[Link]("Enter the side of the cube in centimeter");
Scanner scan=new Scanner([Link]);
int side=[Link]();
[Link]("The surface area of the cube is: "+(6*side*side)+"
square centimeter");
}
}
class MainInheritHier{
public static void main(String[] args){
Shape s;
Square sq=new Square();
Cube cu=new Cube();
s=sq;
[Link]();
s=cu;
[Link]();
}
}

You might also like