Java Assignment-2
Java Assignment-2
Objective: To revise Inheritance and to understand the concepts of Abstract class & Method
overriding in Java.
3. Write a program to create a class named Vehicle having protected instance variables
regnNumber, speed, color, ownerName and a method showData ( ) to show “This is a
vehicle class”. Inherit the Vehicle class into subclasses named Bus and Car having
individual private instance variables routeNumber in Bus and manufacturerName in Car
and both of them having showData( ) method showing all details of Bus and Car
respectively with content of the super class’s showData( ) method.
4. Write a Java program which creates a base class Num and contains an integer number
along with a method showNum( ) which displays the number. Now create a derived class
HexNum which inherits Num and overrides showNum( ) which displays the hexadecimal
value of the number. Demonstrate the working of the classes.
5. Write a Java program which creates a base class Num and contains an integer number
along with a method showNum( ) which displays the number. Now create a derived class
OctNum which inherits Num and overrides showNum( ) which displays the octal value
of the number. Demonstrate the working of the classes.
Create a subclass of this class SavingsAccount and add the following details:
Data Members:
(a) rateOfInterest
Methods:
(a) calculateAmount( )
Create a subclass of this class Car that inherits the class MotorVehicle and add the
following details:
Data Members:
(b) discountRate
Methods:
(a) display( ) - method to display the Car name, model number, price and the discount rate.
(b) discount( ) - method to compute the discount.