OOPs (Object Oriented Programming system) Basic Concepts, Summaries of Computer science

you can learn about the OOPs definition and its features with examples.

Typology: Summaries

2011/2012

Available from 09/12/2023

pratima-mall
pratima-mall 🇮🇳

2 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OOPs Basic Concepts
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:
pf3
pf4
pf5

Partial preview of the text

Download OOPs (Object Oriented Programming system) Basic Concepts and more Summaries Computer science in PDF only on Docsity!

OOPs Basic Concepts

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:

  1. Compile time polymorphism/Method Overloading/Early Binding
  2. Runtime polymorphism/Method Overriding/Late Binding
  3. Compile time polymorphism: When you define more than one method with same name but with different signatures, it is called Compile time polymorphism/Method Overloading. Note: The return type of the methods does not play any role in the method overloading. Example: class Math { public int Sum(int a, int b) { return a+b; } public int Sum(int a, int b, int c) { return a+b+c; } }

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………