Object-oriented programming (OOP) is a programming paradigm that uses “objects” and their interactions to design applications and computer programs. Programming techniques may include features such as abstraction, encapsulation, inheritance, and polymorphism.

It is a problem solving technique to develop software systems.

Class: A class describes all the attributes of objects , as well as the methods that implement the behavior of member objects.

Object: It’s a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects are members of a class.Attributes and behavior of an object are defined by the class definition.

Access keywords: Access keywords define the access to class members from the same class and from other classes. The most common access keywords are:

  • Public: Allows access to the class member from any other class.
  • Private: Allows access to the class member only in the same class.
  • Protected: Allows access to the class member only within the same class and from inherited classes.
  • Internal: Allows access to the class member only in the same assembly.
  • Protected internal: Allows access to the class member only within the same class, from inherited classes, and other classes in the same assembly.
  • Static: Indicates that the member can be called without first instantiating the class.

Abstraction: “Abstraction” simply means showing only those details to the user which are of use to them , and hiding up the unnecessary portion.

Example: When an user uses the ATM he/she thinks that the ATM card is validated by the ATM machine he/she is using
But the user has no idea how it is validated

Encapsulation: Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. In other words, encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions).

Example:
public class Box
{
private int length;
private int width;
private int height;

public void setLength(int p)
{length = p;}

public void setWidth(int p)
{width = p;}

public void setHeight(int p)
{height = p;}

public int displayVolume()
{System.out.println(length*width*height)…
}

public static void main(String args [ ])
{
Box b1=new Box(3,4,5);
b1.displayvolume();
}

Polymorphism: Polymorphism is briefly described as “one interface, many implementations”.

There are two types of polymorphism:

Compile time polymorphism – It is achieved by overloading functions and operators.
Method Overloading
– Method with same name but with different arguments is called method overloading.
– Method Overloading forms compile-time polymorphism.

Example of Method Overloading:
class A1
{
void hello()
{ Console.WriteLine(“Hello”); }

void hello(string s)
{ Console.WriteLine(“Hello {0}”,s); }
}

Run time polymorphism – It is achieved by overriding virtual functions. Method Overriding
– Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.
– Method overriding forms Run-time polymorphism.
– Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. By declaring base class function as virtual, we allow the function to be overridden in any of derived class.

Example of Method Overriding:
Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent
{
override void hello()
{ Console.WriteLine(“Hello from Child”); }
}

static void main()
{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.

Inheritance: Inheritance allows a class to have the same behavior as another class and extend or tailor that behavior to provide special action for specific needs.

Inheritance is achieved by using “Inherits” keyword in VB.NET (For C# it is “:”). There are two classes one is the parent “ClsParent” and second is the child “ClsChild”.Parent class has a string which has to parsed for junk data “@” and “/”.ClsParent has the functionality which parses only cleans up “@”.”ClsChild” then inherits from parent and adds extra functionality by parsing “/”.

public class ClsParent {
    
protected string strData = “jksdhkj@dadad///ajkdhsjakd“;
    public string 
Parse() {
        
string PstrData;
        
PstrData strData;
        
PstrData Replace(PstrData, “@”, ” “);
        return 
PstrData;
    
}
    
public string GetActualString() {
        
return strData;
    
}
}

Above is the source which parses only “@” of strData variable.

public class ClsChild : ClsParent {
    
public void ParseBackSlash() {
        
string PstrData;
        
PstrData = this.Parse();
        
PstrData Replace(PstrData, “/”, ” “);
        return 
PstrData;
    
}
}

Above is the source code for “ClsChild” which does the remaining work.It adds extra functionality by parsing “/” junk character’s of the data.

Note:- Strdata was accessible only because it was defined as protected in the parent class.