repl.it
@kironroy/

encapsulation

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
  • publicmain.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;

   class Rectangle {
      //member variables are private cannot access outside class
      private double length; 
      private double width;
      
      public void Acceptdetails() {
         Console.WriteLine("Enter Length: ");
         length = Convert.ToDouble(Console.ReadLine());
         Console.WriteLine("Enter Width: ");
         width = Convert.ToDouble(Console.ReadLine());
      }
      public double GetArea() {
         return length * width;
      }
      public void Display() {
         Console.WriteLine($"Length: {length}");
         Console.WriteLine($"Width: {width}");
         Console.WriteLine($"Area: {GetArea()}");
      }
   }//end class Rectangle
   
   class ExecuteRectangle {
      static void Main(string[] args) {
         Rectangle rectangle1 = new Rectangle();
         rectangle1.Acceptdetails();
         rectangle1.Display();
         Console.ReadLine();
      }
   }