房天下 > 房天下问答 > 业主生活 > 其他
  • Java-Inheritance and Polymorph

    1. An Airplane is a class used to store the following basic information about an airplane:double myWeight, the weight of the airplane in kilograms;double myLength, the length of the airplane in meters.The Airplane class is defined as follows:public class Airplane { private double myWeight; private double myLength; public Airplane( double weight, double length ) { myWeight = weight; myLength = length; } public double getWeight() { return myWeight; } public double getLength() { return myLength; } }The PassengerJet class extends the Airplane class. It has an additional instance variable, myPassengerCount, that is used to record the maximum number of passengers that can be carried by the airplane.Complete the following definition of PassengerJet:public class PassengerJet extends Airplane{// add an instance variable herepublic PassengerJet( double weight, double length, int passengerCount ){super( weight, length );// initialize the new instance variable here}public int getPassengerCount(){// complete this definition for an accessor method for// the new instance variable}}public static void main( String[] args ){// test your code herePassengerJet p = new PassengerJet( 277000.0, 72.75, 523 );System.out.println( p.getWeight() );System.out.println( p.getLength() );System.out.println( p.getPassengerCount() );}

    提问者:wzfzhh

    发布于2011-02-11

共1个回答
  • dzr689 丨Lv 3
    public class PassengerJet extends Airplane{private int myPassengerCount;public PassengerJet( double weight, double length, int passengerCount ){super( weight, length );myPassengerCount=passengerCount;}public int getPassengerCount(){return myPassengerCount;}}
    +1 2011-02-12 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。