0% found this document useful (0 votes)
2 views

java_cw1

The document outlines the creation of a class hierarchy in Java, starting with a base class 'Shape' and its subclasses 'Rectangle', 'Circle', and 'Square', demonstrating inheritance and method overriding. It also describes the implementation of a 'Vehicle' class with derived classes 'Car' and 'Bike', including a mechanism to instantiate the appropriate class based on user input for the number of tyres. Lastly, it introduces an abstract class 'Bank' with subclasses for different banks, each implementing a method to return their balance.

Uploaded by

Upasna Patel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java_cw1

The document outlines the creation of a class hierarchy in Java, starting with a base class 'Shape' and its subclasses 'Rectangle', 'Circle', and 'Square', demonstrating inheritance and method overriding. It also describes the implementation of a 'Vehicle' class with derived classes 'Car' and 'Bike', including a mechanism to instantiate the appropriate class based on user input for the number of tyres. Lastly, it introduces an abstract class 'Bank' with subclasses for different banks, each implementing a method to return their balance.

Uploaded by

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

1. Create a class named 'Shape' with a method to print "This is This is shape".

Then
create two other classes named 'Rectangle', 'Circle' inheriting the Shape class, both
having a method to print "This is rectangular shape" and "This is circular shape"
respectively. Create a subclass 'Square' of 'Rectangle' having a method to print
"Square is a rectangle". Now call the method of 'Shape' and 'Rectangle' class by the
object of 'Square' class.

2. Create three classes:

Class Vehicle:

Vehicle Class will contain a display() function, which will say "This is a Vehicle".

Class Car:
Car Class will derive the Vehicle Class and overwrite its display() function. it will say
"This is a Car".

Class Bike:

Bike Class will derive the Vehicle Class and overwrite its display() function. it will say "This
is a Bike".

Write an application that reads an Integer N, which will denote the number of tyres in the
vehicle. You have to create an object of the appropriate class according to the value of N and
use it display() function.

If N = 2, Create a Bike Object.

If N = 4, Create a Car Object.

Create a Vehicle Object, otherwise.

Definition of Done:

DoD 1: Each class definition is stored in its own .java file.

DoD 2: Switch statement is used for identifying the appropriate class for which the object is
to be invoked.

3. Create an abstract class 'Bank' with an abstract method 'getBalance'. $100, $150 and
$200 are deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC'
are subclasses of class 'Bank', each having a method named 'getBalance'. Call this
method by creating an object of each of the three classes.

You might also like