Core Java Assignments: 2: Inheritance and Polymorphism
Core Java Assignments: 2: Inheritance and Polymorphism
1. Create an abstract class Instrument which is having the abstract function play.
Create three more sub classes from Instrument which is Piano, Flute, Guitar.
Override the play method inside all three classes printing a message
You must not allow the user to declare an object of Instrument class.
Use the instanceof operator to print that which object stored at which index of
instrument array.
4. Write a program that accepts two numbers and a operator like (+,-,*, /) as command
line arguments and perform the appropriate operation indicated by operator.
If the user enters any other character the appropriate message will be displayed. The
output of the program should be displayed to the user.
5. Create a class Car which contains members speed, noOfGear. The class has a method
drive() which is responsible to provide starting speed and noOfGears to a Car.
Implement display() method which will display all attributes of Car class.
The class SportCar is derived from the class Car which adds new features
AirBallonType. When this method is invoked, initial speed and gear status must be
displayed on console. Override the display method which display all attribute of the
SportCar. Make use of super class display() method.