Advertisement
rshishir11

Classtest Set B Qn4

Jun 28th, 2022
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Example
  4. {
  5.  
  6.   interface Shape
  7.   {
  8.     void getData(int l, int b);
  9.     void displayArea();
  10.   }
  11.  
  12.   class Rectangle : Shape
  13.   {
  14.     private int l;
  15.     private int b;
  16.    
  17.     public void getData(int l, int b)
  18.     {    
  19.       this.l = l;
  20.       this.b = b;
  21.     }
  22.    
  23.     public void displayArea(){
  24.         Console.WriteLine(l*b);
  25.     }
  26.   }
  27.  
  28.   class Square : Shape
  29.   {
  30.     private int l;
  31.    
  32.     public void getData(int l, int b = 0)
  33.     {    
  34.       this.l = l;
  35.     }
  36.    
  37.     public void displayArea(){
  38.         Console.WriteLine(l*l);
  39.     }
  40.   }
  41.  
  42.   class Program
  43.   {
  44.     static void Main(string[] args)
  45.     {
  46.       Rectangle r = new Rectangle();  
  47.       r.getData(5,4);
  48.       r.displayArea();
  49.      
  50.       Square s = new Square();  
  51.       s.getData(5);
  52.       s.displayArea();
  53.      
  54.     }
  55.    
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement