In Java Use inheritance to create the class PassengerPlane. An object of this class includes a model, range, and number of seats. Include a constructor, the appropriate get and set method(s), and a toString method that returns a string containing the model, range, and number of seats for the plan.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Java

Use inheritance to create the class PassengerPlane. An object of this class includes a model, range, and number of seats. Include a constructor, the appropriate get and set method(s), and a toString method that returns a string containing the model, range, and number of seats for the plan.

public class Airplane {
private string model; // Model of this plane (ex. Boeing 767)
private double range; // Range in miles of this plane
public Airplane(String model, double range) {
this.model = model;
this.range = range;
}
public String getModel() { return model; }
public double getRange() { return range; }
public string tostring() {
return model+" “+range+" miles.";
}
}
Transcribed Image Text:public class Airplane { private string model; // Model of this plane (ex. Boeing 767) private double range; // Range in miles of this plane public Airplane(String model, double range) { this.model = model; this.range = range; } public String getModel() { return model; } public double getRange() { return range; } public string tostring() { return model+" “+range+" miles."; } }
Expert Solution
Step 1

Introduction of the Program:

The Java Program uses the concept of inheritance. Here the Airplane class has two fields and the Passenger Plane inherits the fields of the Airplane class and the passenger Plane class has one field and then the program displays the message using the toString method.

Step 2

Source code of the Program: save the below code as Main.java

//Main.java
//Java program to illustrate the concept of inheritance 
  
// base class 
class Airplane 

    // the Airplane class has two fields 
    private String model; 
    private double range; 
          
    // the Airplane class constructor 
    public Airplane(String nModel, double nRange) { 
        this.model = nModel; 
        this.range = nRange; 
    } 
    
    public String getModel(){return model;}
    public double getRange(){return range;}
      
    // toString() method to print info of Bicycle 
    public String toString()  
    { 
        return("Airplane model "+model
                +"\n"
                + "Range "+range+" miles"); 
    }  

  
// derived class PassengerPlane inherits Airplane class
class PassengerPlane extends Airplane

      
    // the PassengerPlane subclass adds one more field 
    public int seat; 
  
    // the PassengerPlane subclass has one constructor 
    public PassengerPlane(String model,double range, 
                        int startHeight) 
    { 
        // invoking base-class(Airplane) constructor 
        super(model, range); 
        seat = startHeight; 
    }  
          
    // the PassengerPlane subclass adds one more method 
    public void setHeight(int newValue) 
    { 
        seat = newValue; 
    }  
      
    // overriding toString() method 
    // of Airplane to print more info 
    @Override
    public String toString() 
    { 
        return (super.toString()+ 
                "\nNumber of seat is "+seat); 
    } 
      

  
// driver class 
public class Main

    public static void main(String args[])  
    {   
        PassengerPlane obj = new PassengerPlane("Boeing 767", 450.90, 280); 
        System.out.println(obj.toString()); 
              
    } 

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education