abstract class Container{
double r;
public abstract double volume();
}
class cube extends Container{//立方体
public cube(double r1){
r=r1;
}
public double volume(){
return r*r*r;
}
void hh(){
System.out.println("立方体的体积是:"+ volume());
}
}
class sphere extends Container{//球体
public sphere(double r2){
r=r2;
}
public double volume(){
return Math.PI*r*r*r*(4/3);
}
void hh(){
System.out.println("球体的体积是:"+volume());
}
}
class cylinder extends Container{//圆柱体
public cylinder(double r3){
r=r3;
}
public double volume(){
return Math.PI*r*r*r;
}
void hh(){
System.out.println("圆柱体体积是:"+volume());
}
}
class Tiji{
public static void main(String args[]){
cube c1=new cube(3.0);
sphere s1=new sphere(5.0);
cylinder c=new cylinder(6.0);
c1.hh();//或者把该语句替换成System.out.println("立方体的体积是:"+c1.volume())把hh()制空
s1.hh();
c.hh();
}
}
double r;
public abstract double volume();
}
class cube extends Container{//立方体
public cube(double r1){
r=r1;
}
public double volume(){
return r*r*r;
}
void hh(){
System.out.println("立方体的体积是:"+ volume());
}
}
class sphere extends Container{//球体
public sphere(double r2){
r=r2;
}
public double volume(){
return Math.PI*r*r*r*(4/3);
}
void hh(){
System.out.println("球体的体积是:"+volume());
}
}
class cylinder extends Container{//圆柱体
public cylinder(double r3){
r=r3;
}
public double volume(){
return Math.PI*r*r*r;
}
void hh(){
System.out.println("圆柱体体积是:"+volume());
}
}
class Tiji{
public static void main(String args[]){
cube c1=new cube(3.0);
sphere s1=new sphere(5.0);
cylinder c=new cylinder(6.0);
c1.hh();//或者把该语句替换成System.out.println("立方体的体积是:"+c1.volume())把hh()制空
s1.hh();
c.hh();
}
}