OOPS-CONCEPTS

OOPS Concepts: Object Oriented Programming System

Hello Friends,

In this blog post, I am going to discuss the OOPS concepts.

Almost all techie peoples whether they are students or professional are aware of this OOPS concepts.

these concepts are useful for passing the academic exams, interview for the job, a job at the workplace.

If you are sound enough with OOPS concepts then you can design a software or application at ease.

Now, the question is, what are these OOPS concepts……?

There are various concepts in OOPS listed below:

Object
Class
Inheritance
Polymorphism
Data Abstraction
Encapsulation


class-object

 

Object:

It can be anything that you can touch and feel, it has a real-time existence. It is also known as an instance of the class.

It also possesses some property like:

1. Identity
2. State
3. Behaviour
4. Characteristic

MyObject object = new MyObject(); ----> Declaration of object of class "MyObject"

Class:

A class is a blueprint for objects OR class is a collection of objects which is a logical entity.

Class does not have a real-time existence.

For example, Tree is a class and tree at my house is its instance or object, a tree at the garden is second instance or object.

Class Sample

{
int id =”401″;

String name =”sample”; ————————-> syntax of class

}


Inheritance:

Generalization to specification is called Inheritance. Make it more simple, using the property of base class into

the subclass is called inheritance. If still not clear then I give you a real life example.

Google might be the best example to make it understand as all of us are familiar with Google.

Let’s assume Google is a base class and you make your account at google.

Gmail, Google drives, youtube and etc. are the subclass, So for using the facilities you need a google account,

As you already have made Google account into your base class then you can use that account to login into these base classes accounts.

So here google account is your base class properties which you used to access the base class features or properties.

 

full-inheritance

In this concept, the behavior is taken from the parent class and used in the subclass.


Types of Inheritance:

Single Inheritance:

simple-inheritance

//Base Class
class Vehicle
{
public void testvehicle()
{
//TO DO:
}
}

//Derived Class
class Car : Vehicle
{
public void testCar()
{
//TO DO:
}
}


Multilevel Inheritance:

multilevel-inheritance

//Base Class
class Animal
{
public void testAnimal()
{
//TO DO:
}
}

//Derived Class
class Mammal : Animal
{
public void testMammal()
{
//TO DO:
}
}

//Derived Class
class Human : Mammal
{
public void testHuman()
{
//TO DO:
}
}


Multiple Inheritance:

 

JAVA and DOT NET(C#, F# and etc.) does not support multiple inheritance.
multiple-inheritance

//Base Class
class Person
{
public void testPerson()
{
//TO DO:
}
}

//Base Class
class Employee
{
public void testEmployee()
{
//TO DO:
}
}

//Derived Class
class Teacher : Person, Employee
{
public void testTeacher()
{
//TO DO:
}
}


Multipath Inheritance:

JAVA and DOT NET(C#, F# and etc.) does not support multiple inheritance.

multipath-inheritance

//Base Class
class Student
{
public void testStudent()
{
//TO DO:
}
}

//Derived Class
class InternalExam  : Student
{
public void testInternalExam()
{
//TO DO:
}
}

//Derived Class
class ExternalExam : Student
{
public void testExternalExam()
{
//TO DO:
}
}

//Derived Class
class Result : InternalExam, Student, ExternalExam
{
public void testResult()
{
//TO DO:
}
}


Hirarichal Inheritance:

hirarichal-inheritance

//Base Class
class Father
{
public void testFather()

{
//TO DO:
}
}

//Derived Class
class Son-1 : Father
{
public void testSon-1()
{
//TO DO:
}
}

//Derived Class
class Son-2 : Father
{
public void testSon-2()
{
//TO DO:
}
}

//Derived Class
class Daughter : Father
{
public void testDaughter()
{
//TO DO:
}
}


Hybrid Inheritance:

JAVA and DOT NET(C#, F# and etc.) does not support multiple inheritance.

hybrid-inheritance

//Base Class
class Cricketer
{
public void testCricketer()
{
//TO DO:
}
}

//Derived Class
class Bowler : Cricketer
{
public void testBowler()
{
//TO DO:
}
}

//Derived Class
class Batsman : Cricketer
{
public void testBatsman()
{
//TO DO:
}
}

//Derived Class
class Allrounder : Bowler, Batsman
{
public void testAllrounder()
{
//TO DO:
}
}


Polymorphism:

One function many forms, One character multiple roles.

Here one function is used for multiple works either by overloading or overriding.

Polymorphism is further classified into two types.

1. Compile time Polymorphism/ Function overloading within the same class/compile time binding/ static binding:

It is known with many names so don’t confuse with the name, they all are same as given above in heading.

In Static Polymorphism, the function with the same name is overloaded with a different parameter or with a different signature.

If we see the real life example then pressure cooker would be the best example for this.

It belongs to the utensils class and considers cooker as a function.

When we supply rice as a parameter then rice then the outcome is rice and when we supply pulse into the cooker the outcome is a pulse.

See the image below:

staticpolymorphism



2. Runtime Polymorphism/ Dynamic Polymorphism/ function overriding in different classes/ dynamic binding:

In Dynamic Polymorphism, the function with the same signature is overridden in two different classes.

See the real life example,  Water filter have different classes like hot water point, cold water point, normal water point.

All function working is same to give water but the output is different. We decide this at runtime that which type of water we need.

See the image below:

runtime-polymorphism


Data Abstraction:

It is schema where essential properties are shown at the front end and remaining are kept at behind the screen.

For an example, in car making the engine, wiring and other complex part are kept hidden or under the bonnet as user

does not have to deal with it whereas the steering, dashboard, meter sound system light are kept outside, in front of the user so that he can use that efficiently.

And another good example is we ourself, As we have all quality inside us like anger, mood, happiness, sadness and

etc. But we always show our best side or good behavior Infront of others until or unless we need to show real feelings.

See the image below:

dataabstraction


Encapsulation:

Wrapping of data member and a member function is called encapsulation or keeping the variables and functions in one class.

It is like a capsule which contains various medicines mix together in it.

See the image below:

encapsulation
Please keep reading our blogs for new updates.

In a case of any queries, you can write us at anurag@a5theory.com we will get back to you ASAP.

Hope! you would have enjoyed this post.

Please feel free to give your important feedbacks in the comment section below.

Have a great time! Sayonara!

Author:

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.