• 十一周上机


    public  class Vehicle {
    public String brand;
    public String color;
    public double speed=0;
    void setVehicle(String brand,String color) {
        this.brand=brand; 
        this.color=color;    
    }
    void access(String brand,String color,double speed) {
        this.brand=brand;
        this.color=color;
        this.speed=speed;
    }
    void run() {
        System.out.println("该汽车的品牌为:"+this.brand+"颜色为:"+this.color+"速度为"+this.speed);
    }
    }
    复制代码
    复制代码
    public class VehicleTest {
    public static void main(String args[]) {
        Vehicle c;
        c=new Vehicle();
        c.setVehicle("benz", "yellow");
        c.run();
        c.access("benz", "black", 300);
        c.run();
    }
    }
    复制代码
    复制代码
    public class Car extends Vehicle {
        int loader;
        void access(String brand,String color,double speed,int loader) {
            this.brand=brand;
            this.color=color;
            this.speed=speed;
            this.loader=loader;
        }
        void run() {
            System.out.println("该汽车的品牌为:"+this.brand+"颜色为"+this.color+"速度为"+this.speed+"核载人数"+this.loader);;
        }
    }
    复制代码
    复制代码
    public class Test {
    public static void main(String args[]) {
        Car c;
        c=new Car();
        c.access("Honda", "red", 300, 2);
        c.run();
    }
    }
    package pika;
    
    public abstract class Shape {
        private double area;
        private double per;
        private String color;
        public Shape() {
            super();
        }
        public Shape(String color) {
            super();
            this.color = color;
        }
        public abstract double getArea() ;
    
        public abstract double getPer();
    
        public abstract String showAll() ;
        
        public void getColor(String color) {
            this.color=color;
        }
        
    }
    复制代码
    复制代码
    package pika;
    
    public class Rectangle extends Shape{
        private int Width;
        private int height;
        
        public Rectangle() {
            super();
        }
    
        public Rectangle(int width, int height ,String color) {
            super();
            Width = width;
            this.height = height;
            
        }
    
        @Override
        public double getArea() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public double getPer() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public String showAll() {
            // TODO Auto-generated method stub
             String a ="周长是"+(Width+height)*2+"面积是"+Width*height;
            return a;
        }
    
    }
    复制代码
    复制代码
    package pika;
    
    public class Circle extends Shape {
        private int radius;
        
        public Circle(int radius) {
            super();
            this.radius = radius;
        }
    
        public Circle(String color) {
            super();
        }
    
        @Override
        public double getArea() {
            // TODO Auto-generated method stub
            return radius*radius*3.14;
        }
    
        @Override
        public double getPer() {
            // TODO Auto-generated method stub
            return 2*3.14*radius;
        }
    
        @Override
        public String showAll() {
            // TODO Auto-generated method stub
            String a ="周长是"+2*3.14*radius+"面积是"+radius*radius*3.14;
            return a;
        }
        
    }
    复制代码
    复制代码
    package pika;
    
    public class hello {
        public static void main(String[] args) {
            Circle c = new Circle(5);
            Rectangle r = new Rectangle(5,5,"baise");
            System.out.println(c.showAll());
            System.out.println(r.showAll());
        }
    }
  • 相关阅读:
    空悬指针、野指针、内存泄漏、内存溢出
    自定义消息的操作方法ON_MESSAGE(..)
    为什么static成员变量一定要在类外初始化?
    Ubuntu 系统目录结构
    Beyond Compare 4 30天评估期结束的解决办法
    C++ string 字符串 结尾 标志
    C语言——枚举类型用法
    结构体struct-联合体union-枚举enum
    网卡bood
    kvm 安装
  • 原文地址:https://www.cnblogs.com/SmileMRzhang/p/12888312.html
Copyright © 2020-2023  润新知