Advertisement
_vish_99__

Constructor Problem

Jul 6th, 2022
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. namespace NM1
  2. {
  3.     public class Rectangle
  4.     {
  5.  
  6.         //variables
  7.         private int length;
  8.         private int breadth;
  9.  
  10.         //getters setters
  11.  
  12.         public int Length
  13.         {
  14.             get { return length; }
  15.             set { length = value; }
  16.         }
  17.         public int Breadth
  18.         {
  19.             get { return breadth; }
  20.             set { breadth = value; }
  21.         }
  22.  
  23.  
  24.         // WHEN THE CONSTRUCTOR IS DEFINED HERE THE ERROR ARISES IN THE INHERITED CLASS
  25.         public Rectangle(int passedLength, int passedBreadth)
  26.         {
  27.             this.length = passedLength;
  28.             this.breadth = passedBreadth;
  29.         }
  30.  
  31.         public void rectangleArea()
  32.         {
  33.             Console.WriteLine("The area of the rectangle is : " + (Length * Breadth));
  34.         }
  35.     }
  36.  
  37. }
  38. namespace NM2
  39. {
  40.     public class Square : NM1.Rectangle
  41.     {
  42.  
  43.         public void calculateSquare()
  44.         {
  45.             Console.WriteLine("The length is inherited from rectangle : ---> " + this.Length);
  46.             Console.WriteLine("The area of the sqaure is : " + (this.Length * this.Length));
  47.         }
  48.  
  49.     }
  50.  
  51.  
  52.     class programs
  53.     {
  54.         public static void Main()
  55.         {
  56.             Square s = new Square();
  57.             s.Length = 12;
  58.             s.Breadth = 14;
  59.             s.calculateSquare();
  60.             s.rectangleArea();
  61.         }
  62.     }
  63.  
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement