VehicleInterface (Interface), Vehicle (abstract class), Car (Class)

解决方案 »

  1.   

    public interface VehicleInterface{
      public void run();
    }public abstract class Vehicle implements VehicleInterface{
      public void run(){
      }
    }public class Car extends Vehicle{
      public void run(){
        super.run();
      }
    }
      

  2.   

    大神帮忙给修改补充一下?
    public interface VehicleInterface {
    public abstract void start();
    public abstract void stop();
    }==================================
    public abstract class Vehicle implements VehicleInterface {
    int registrationNumber;
    Person owner;
    private String brand;
    Double price; void transferOwnership(Person newOwner) { }
    }class Person {}
    ====================================public class Car extends Vehicle{
    private int id;
    private int colorId;
    int numberOfDoors;
     
     
    public Car() {
    super();
    System.out.println("inside the constructor");
    }

    setId(id){};
    getId(){};

     
     

    public void start(){

    }

           public void stop(){

    }
    }
      

  3.   


    上面2句1&2必须有吗?
      

  4.   

     1可以用
    abstract public void run();
    吗?
      

  5.   


    我试了一下,如果是abstract class,可以不写public void run(){  }但如果不是abstract class,则一定要写public void run(){  }
    到底应不应该用abstract class?