Object Oriented Programming(OOPs)

Encapsulation:
It is the process of hiding all the internal details of objects from the outside world

Abstraction:
It talks about hiding the complexity of code by providing set of interfaces to consume the functionality
Hiding the unnecessary things and revealing when it needs

Inheritance:
Reusing parent class variables and method along with child class variables and methods will be used while creating the child object is called "Inheritance"
Base class
Derived class
Base class: The class which is allowing others to inherit fields or methods is called "Base class"
Derived class: The class which is inherited fields or methods from other class is called "Derived class"

What is the use of Inheritance:
Using Inheritance concept reduce the development time and better maintenance

Polymorphism:
Having multiple forms
To ability to appear in many forms
same operation may behave differently on different classes
We have two types
  • Compile time polymorphism(Method overloading)
  • Run time polymorphism(Method overriding)
 Method Overloading:
The methods with in the class can have the same name but different in their parameter list and return type
Ex: class A
      {
         public void Add()
         {}
         public int Add()
         {}
         public void Add(int x)
         {}

      }

Method Overriding:
If a method of parent class redefining under its child classes with the same signature
Ex:
class BC
    {
        public virtual  void Display()
        {
            System.Console.WriteLine("BC::Display");
        }
    }

    class DC : BC
    {
        public override  void Display()
        {
            System.Console.WriteLine("DC::Display");
        }
       
    }

    class Demo
    {
        public static void Main()
        {

            BC b = new BC();
            b.Display();

            DC d = new DC();
            d.Display();
            BC  dd = new DC();
            dd.Display();
            Console.ReadLine();
        }
    }

output :

BC : Display
DC : Display
DC : Display

Without Method Overriding

BC : Display
DC : Display
BC : Display


No comments:

Post a Comment