Java代码:
寻乌网站建设公司创新互联建站,寻乌网站设计制作,有大型网站制作公司丰富经验。已为寻乌上千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的寻乌做网站的公司定做!
class Point {
protected int x;
protected int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
class Circle extends Point {
protected int radius;
public Circle(int x, int y, int radius) {
super(x, y);
this.radius = radius;
}
public double area() {
return Math.PI * radius * radius;
}
public double perimeter() {
return 2 * Math.PI * radius;
}
}
class Cylindar extends Circle {
protected int height;
public Cylindar(int x, int y, int radius, int height) {
super(x, y, radius);
this.height = height;
}
public double volumn() {
return area() * height;
}
}
public class Main {
public static void main(String[] args) {
Point p1 = new Point(3, 4);
Point p2 = new Point(5, 6);
Circle c1 = new Circle(0, 0, 3);
Cylindar cy1 = new Cylindar(0, 0, 3, 4);
System.out.println("圆c1的面积:" + c1.area());
System.out.println("圆c1的周长:" + c1.perimeter());
System.out.println("圆柱体cy1的体积:" + cy1.perimeter());
}
}
运行测试:
圆c1的面积:28.274333882308138
圆c1的周长:18.84955592153876
圆柱体cy1的体积:18.84955592153876
可运行的:
import java.awt.*;
import java.awt.event.*;
public class BackJFrame extends Frame{
public BackJFrame(){
super("台球");
setSize(300,300);
setBackground(Color.cyan); //背景
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{System.exit(0);}
} );
}
public static void main(String args[]){
new BackJFrame();
}
}
第一个:
public class Yaojing {
protected String name;
protected int age;
protected String gender;
public void showBasicInfo() {
System.out.println(toString());
}
public void eatTangSeng() {
System.out.println("吃饱了");
}
@Override
public String toString() {
return "Yaojing [name=" + name + ", age=" + age + ", gender=" + gender + "]";
}
}
第二个类
public class Zhizhujing extends Yaojing {
public void buildNet(){
System.out.println("蜘蛛在织网");
}
}
第三个类
public class Baigujing extends Yaojing {
public void beBeauty(){
System.out.println("白骨精");
}
}