Note: It`s python coding 1. Class Implementation a) Implement a class Rectangle with two attributes, width and height. b) Implement an init method with an optional parameter type. Set the default value of the attributes of width and height to 1. c) Implement a display method to print the values of width and height. d) Instantiate two objects of type rectangle, one with arguments one without. r1 = Rectangle(4, 5) r2 = Rectangle() e) Call display() to print width and height. Example Output Width: 4 Height: 5 Width: 1 Height: 1
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Note: It`s python coding
1. Class Implementation
a) Implement a class Rectangle with two attributes, width and height.
b) Implement an init method with an optional parameter type.
Set the default value of the attributes of width and height to 1.
c) Implement a display method to print the values of width and height.
d) Instantiate two objects of type rectangle, one with arguments one without.
r1 = Rectangle(4, 5)
r2 = Rectangle()
e) Call display() to print width and height.
Example Output
Width: 4
Height: 5
Width: 1
Height: 1
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images