67% found this document useful (3 votes)
572 views

Java Assignment-2

The document outlines an assignment on programming in Java that involves: 1) Demonstrating method overloading and overriding through programs. 2) Creating subclasses Vehicle, Bus, and Car to inherit from the Vehicle superclass and override methods. 3) Creating subclasses HexNum and OctNum that inherit from the Num superclass and override a method to display values in hexadecimal and octal formats. 4) Creating abstract superclass Accounts and subclass SavingsAccount, with the subclass adding new data members and methods. 5) Creating abstract superclass MotorVehicle and subclass Car, with the subclass inheriting from the superclass and adding new data members and methods.

Uploaded by

Animesh Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
572 views

Java Assignment-2

The document outlines an assignment on programming in Java that involves: 1) Demonstrating method overloading and overriding through programs. 2) Creating subclasses Vehicle, Bus, and Car to inherit from the Vehicle superclass and override methods. 3) Creating subclasses HexNum and OctNum that inherit from the Num superclass and override a method to display values in hexadecimal and octal formats. 4) Creating abstract superclass Accounts and subclass SavingsAccount, with the subclass adding new data members and methods. 5) Creating abstract superclass MotorVehicle and subclass Car, with the subclass inheriting from the superclass and adding new data members and methods.

Uploaded by

Animesh Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Assignment- 2

Subject: Programming in JAVA (BCA-CC201)


Submission Date: 12/04/2020

Objective: To revise Inheritance and to understand the concepts of Abstract class & Method
overriding in Java.

1. Write a Java program to show method overloading.

2. Write a Java program to show method overriding.

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.

6. Create an abstract class Accounts with the following details:


Data Members:
(a) Balance
(b) accountNumber
(c) accountHoldersName
(d) address
Methods:
(a) withdraw( ) – abstract method
(b) deposit( ) – abstract method
(c) display( ) – method to show the balance of the account number.

Create a subclass of this class SavingsAccount and add the following details:

Data Members:
(a) rateOfInterest
Methods:
(a) calculateAmount( )

7. Create an abstract class MotorVehicle with the following details:


Data Members:
(a) modelName
(b)modelNumber
(c) modelPrice
Methods:
(a) display( )- to show all the details

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.

You might also like