



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
you can learn about the OOPs definition and its features with examples.
Typology: Summaries
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Definition:
Object Oriented Programming (OOP) in C# is a concept of modern programming language that allows programmers to organize entities (Class) and objects.
OOPs is all about creating and working on objects that contains data and methods.
Object programming language allows you to change or add new features and it is reusable, well-structured and easy to use, debug and test. OOPs has four basic principles. Let’s understand each one by one. Abstraction: It defines an abstract representation of a system, meaning hiding certain details and showing essential information to the user. Real World Example of Abstraction: Suppose you have two Vehicles as following: Bike (Features: Gear, 2 wheels, Handle) Car (Features: Gear, 4 wheels, Steering) Abstract information (necessary and common information) for the Vehicle object is that both have Gear feature. So for the Vehicle object, you will have abstract class as following:
abstract class Vehicle { public void Gear(); } public class Bike : Vehicle { public void TwoWheels(); public void Handle(); } public class Car : Vehicle { public void FourWheels(); public void Steering(); } Encapsulation: It hides the internal state and functionality of an object, meaning it hides the implementation details and only allowing access through a public set of functions. In Layman’s term, Wrapping up a data member and a method together into a single unit is called Encapsulation. For Example: Encapsulation is just like a box in which you can keep your pen, pencil, eraser and sharpener so it hides all the things kept inside the box and thus we can conclude that Encapsulation hides the data for security, such as making the variables private and exposes the property to access the private data that will be public.
public class Child : Parent { public Child() { Console.WriteLine(“Child”); } public static void Main() { Child obj = new Child(); obj.Print(); } } Output: Parent Child Print Polymorphism: Polymorphism means one name, many forms. Polymorphism in C# is the process to implement inherited properties or methods in different ways across multiple abstractions.
Polymorphism is of two types:
Console.WriteLine(“I am Yellow”); } } Note: In the Red class, the method Color() is defined with virtual keyword, that means it can be overridden in the derived class. In the Yellow class, the method Color() is redefined with the override keyword. To be continued in next book………