OOPS Concepts: Object-Oriented Programming System2019 / What is the OOPs concept with example..? / What are the main features of OOP?

Hello Friends,

In this blog post, I am going to discuss the OOPS concepts, and what are the main features of OOP?.

Almost all techie peoples whether they are students or professionals are aware of these OOPS concepts.

Why are OOPs used?

these concepts are useful for passing the academic exams, interview for the job, a job at the workplace. OOP’s concepts create the basic foundation in programming and make it very easier.

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

Now, the question is, what are these OOPS concepts……? / What are the 4 basics of OOP?

There are various concepts in OOPS listed below:

Object
Class
Inheritance
Polymorphism
Data Abstraction
Encapsulation


class-object

1. OOPS Concept – 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"

2. OOPS-Concept – 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, a Tree is a class, and the tree at my house is its instance or object, a tree at the garden is the second instance or object.

Class Sample

{
int id =”401″;

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

}


3. OOPS Concept – Inheritance:

The generalization to specification is called Inheritance. Make it more simple, using the property of the 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 understandable as all of us are familiar with Google.

Let’s assume Google is a base class and you make your account on 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 to these base class 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()
{
//TODO:
}
}

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


Multilevel Inheritance:

multilevel-inheritance

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

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

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


Multiple Inheritance:

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

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

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

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


Multipath Inheritance:

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

multipath-inheritance

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

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

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

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


Hirarichal Inheritance:

hirarichal-inheritance

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

{
//TODO:
}
}

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

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

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


Hybrid Inheritance:

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

hybrid-inheritance

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

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

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

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


4. OOPS Concept – 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 the 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 a pressure cooker would be the best example of this.

It belongs to the utensils class and considers the 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 has different classes like hot water point, cold water point, normal water point.

All function working is the 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


5. OOPS Concept – Data Abstraction:

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

For example, in-car making the engine, wiring, and other complex part are kept hidden or under the bonnet as the 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 ourselves, As we have all quality inside us like anger, mood, happiness, sadness and

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

See the image below:

dataabstraction


6. OOPS Concept- Encapsulation:

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

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

See the image below:

encapsulation
Please keep reading our blogs for new updates.

Conclusion:

So here in this blog post of OOP’s concepts, we have learned what are the 4 basics of OOP..? What is the OOPs concept with example? What are the main features of OOP?  What is OOPs in C++? Why are OOPs used?. You have known about Object, Class, Inheritance, Polymorphism, Data Abstraction, Encapsulation.

OOPs, concepts are mostly asked questions in either job interview or in your college viva. And these OOPS concepts build the foundation in your programming language. You can easily make complex and flexible programs in any language if you have a sound knowledge of OOPs concepts. OOPs, concepts are very popular in technical studies of programs and software building.

In case of any queries, you can write to us at A5thoerys@gmail.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!

Anurag

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.