Question 1
Complete the Java code that uses the concept of inheritance to demonstrate dynamic method dispatching.
Class AirPlane has the following members:
- Private instance variable
model - Constructor to initialize
model - Accessor method for
model - Method
displayto display the text:Inside an anonymous airplane
Classes Boeing and AirBus should be defined in such a way that any object of Boeing or AirBus can be assigned to a reference variable of type AirPlane. See the main method to understand the context.
- For an object of
Boeing, methoddisplayshould print the messageInside Boeingfollowed by the model of the Boeing. - For an object of
AirBus, methoddisplayshould print the messageInside AirBusfollowed by the model of the AirBus.
What you have to do:
- Define an accessor method for
modelinside classAirPlane - Define method
displayinside classAirPlane - Define classes
BoeingandAirBus