• 十一周上机


    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());
        }
    }
  • 相关阅读:
    列表、元组、字典的常用操作及内置方法
    可变不可变类型,数字类型及其常用操作,字符串类型及其常用操作
    php cgi&fastcgi&php-fpm
    (3) IOC容器
    str_replace与preg_replace性能对比
    Iterator && IteratorAggregate区别
    php标签
    (2)自动加载
    (1)thinkphp&laravel&swoft目录结构之说
    小程序上传帖子(含有文字图片的微信验证)
  • 原文地址:https://www.cnblogs.com/SmileMRzhang/p/12888312.html
Copyright © 2020-2023  润新知