Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Java Online

abstract class shape{
abstract void draw();
 abstract int area();
}

class square extends shape{
int side;
square(int s){
side=s;
}
int area(){
return side*side;
}
void draw(){
System.out.println("square");
}
}

class circle extends shape{
int radius;
circle(int r){
radius=r;
}
int area(){
return radius*radius;
}
void draw(){
System.out.println("circle");
}
}

class rectangle extends shape{
    int n1;
    int n2;
rectangle(int l,int h){
n1=l;
n2=h;
}
int area(){
return n1*n2;
}
void draw(){
System.out.println("rectangle");
}
}

public class test{
public static void main(String args[]){
shape a=new square(4);
shape b=new rectangle(5,6);
circle c=new circle(3);
System.out.println(a.area());
System.out.println(b.area());
System.out.println(c.area());
}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.