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

Polymorphism_LabTask

The document outlines the structure of classes for shapes, including Shape, Rectangle, and Triangle, each with constructors and a method to calculate area. It also describes a Vehicle class with subclasses Bike and Car, detailing their constructors and methods, emphasizing polymorphic behavior in the main method. The main methods in both sections demonstrate the use of object references to showcase polymorphism with the respective classes.

Uploaded by

valknew123
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

Polymorphism_LabTask

The document outlines the structure of classes for shapes, including Shape, Rectangle, and Triangle, each with constructors and a method to calculate area. It also describes a Vehicle class with subclasses Bike and Car, detailing their constructors and methods, emphasizing polymorphic behavior in the main method. The main methods in both sections demonstrate the use of object references to showcase polymorphism with the respective classes.

Uploaded by

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

Shape

double height
double width
public Shape()
public Shape(…)
public void calculateArea()

Rectangle
public Rectangle()
public Rectangle(…)
public void calculateArea()

Triangle
public Triangle()
public Triangle(…)
public void calculateArea()

Main
In main method create an object reference of Shape and then by storing object of Rectangle and
Triangle respectively show the polymorphic behavior.

2.

Vehicle
String name
int plateNumber
int wheelNumber
public Vehicle()
public Vehicle(name, plateNumber, wheelNumber)
public void start()
public void break()
public void stop()
public void show()

Bike[child class of Vehicle]


String brandName
public Bike()
public Bike(name, plateNumber, wheelNumber,brandName)
/* IT WILL OVERRIDE ALL THE METHODS FROM IT’S PARENT CLASS*/
Car[child class of Vehicle]
String brandName
int seatNumber
public Car()
public Bike(name, plateNumber, wheelNumber,brandName,seatNumber)
/* IT WILL OVERRIDE ALL THE METHODS FROM IT’S PARENT CLASS*/

Main
In main method create an object reference of Vehicle and then by storing object of Bike and Car
respectively show the polymorphic behavior.

You might also like