房天下
>
房天下问答
>
业主生活
>
其他0$房天下问答|Java-Inheritance and Polymorph$https://m.fang.com/ask/ask_1918729.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.pngpackc/pages/ask/detail/detail?askid=1918729
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() );}
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;}}