Solution Review: Implement the Rectangle Class
This review provides a detailed analysis to solve the 'Implement the Rectangle Class using the Concepts of Encapsulation' challenge.
We'll cover the following...
We'll cover the following...
Solution
Press + to interact
C#
// Class Rectangleclass Rectangle {// Private Fieldsprivate int _length;private int _width;// Parameterized Constructorpublic Rectangle(int length, int width) {this._length = length;this._width = width;}// Method to calculate Area of a rectanglepublic int GetArea() {return this._length * this._width;}}class Program {public static void Main(){Rectangle obj = new Rectangle(2,2);System.Console.WriteLine(obj.GetArea());}}
Explanation
The solution is straightforward.