// End of Encapsulation public void Main() { Console.WriteLine("Encapsulation \n"); Console.WriteLine( "Encapsulation is the mechanism that binds together the code and the data it manipulates, and keeps both safe from outside interference and misuse. " + "In OOP, code and data may be combined in such a way that a self-contained box is created. When code and data are linked together in this way, an object is created and encapsulation exists. \n" + "Within an object, code, data or both may be private or public to that object. Private code or data may not be accessible by a piece of the program that exists outside the object. " + "When the code and data is public, other portions of your program may access it even though it is defined within an object. "); //instance created Encapsulation obj = new Encapsulation(20); obj.MySquare(); Console.WriteLine("------------------------------------------------------------------------"); }
private static void OOPOverview() { Console.WriteLine("(1) Classes and Objects"); Console.WriteLine("(2) Creating and accessing Class Component Library"); Console.WriteLine("(3) Constructor and Destructor"); Console.WriteLine("(4) Function Overloading"); Console.WriteLine("(5) Encapsulation"); Console.WriteLine("(6) Inheritance"); Console.WriteLine("(7) Virtual and Hiding Methods"); Console.WriteLine("(8) Abstract Classes"); Console.WriteLine("(9) Sealed Classes"); Console.WriteLine("(10) Interface"); Console.WriteLine("(11) Polymorphism"); var result = Console.ReadLine(); switch (result) { case "1": var a = new OOP.ClassesAndObjects(); a.Main(); break; case "2": var b = new OOP.CreatingClassLibrary(); b.Main(); break; case "3": var c = new OOP.ConstructorAndDestructor(); c.Main(); break; case "4": var d = new OOP.FunctionOverloading(); d.Main(); break; case "5": var e = new OOP.Encapsulation(); e.Main(); break; case "6": var f = new OOP.Inheritance(); f.Main(); break; case "7": var g = new OOP.VirtualAndHidingMethods(); g.Main(); break; case "8": var h = new OOP.AbstractClass(); h.Main(); break; case "9": var i = new OOP.SealedClass(); i.Main(); break; case "10": var j = new OOP.Interface(); j.Main(); break; case "11": var k = new OOP.Polymorphism(); k.Main(); break; } }