zoukankan      html  css  js  c++  java
  • java实训

    4、编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功能。

    class Vehicle{
     int wheels;
     int weight;
     public void a1(){
      System.out.println("车轮数:"+wheels+" 车重:"+weight);
     }
    }
    class car extends Vehicle{
     int wheels;
     int weight;
     int loader;
     public void a2(){
      System.out.println("车轮数:"+wheels+" 车重:"+weight+" 有载人数:"+loader);
     }
    }
    class Truck extends car{
     int wheels;
     int weight;
     int loader;
     int payload;
     public void a3(){
      System.out.println("车轮数:"+wheels+" 车重:"+weight+" 有载人数:"+loader+" 车载重:"+payload);
     }
    }
    public class Test {
     public static void main(String[] args) {  
      Truck e=new Truck();
      e.loader=4;
      e.payload=30;
      e.weight=50;
      e.wheels=4;
      e.a3();
     }
    }
     
  • 相关阅读:
    Attributes in C#
    asp.net C# 时间格式大全
    UVA 10518 How Many Calls?
    UVA 10303 How Many Trees?
    UVA 991 Safe Salutations
    UVA 10862 Connect the Cable Wires
    UVA 10417 Gift Exchanging
    UVA 10229 Modular Fibonacci
    UVA 10079 Pizza Cutting
    UVA 10334 Ray Through Glasses
  • 原文地址:https://www.cnblogs.com/LYY1084702511/p/10817019.html
Copyright © 2011-2022 走看看