Hello Friends, In this blog post(What is the OOPs concept with example), I am going to discuss the OOPS concepts, and what are the main features of OOP.
Almost all techie people whether they are students or professionals are aware of these OOPS concepts(What is the OOPs concept for example).
In this blog post(What is the OOPs concept with example), we are going to cover a few important questions related to the OOPS concepts:
What are OOP concepts?
What is the OOPs concept for example?
What are the 4 basic concepts of object-oriented programming?
How can I learn OOP concepts easily?
Why are OOPs used?
What is polymorphism in OOPs?
What is the full form of OOPs?
Why are OOPs used?|What is the OOPs concept for example?
these concepts are useful for passing academic exams, interviewing for a job, or a job at the workplace.
OOP’s concepts create the basic foundation in programming and make it much easier|What is the OOP concept with example|
If you are sound enough with OOPS concepts then you can design software or applications at ease|What is the OOPs concept with example|
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
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 properties 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 a 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, and a tree in 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. To make it more simple, using the property of the base class in
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, etc. are the subclass, So to use the facilities you need a Google account,
As you already have made a Google account in your base class then you can use that account to log in 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.
In this concept, the behavior is taken from the parent class and used in the subclass.
Types of Inheritance:
Single Inheritance:
Single inheritance has one base class and one derived class. The derived class inherits the properties of the base class or parent class and uses them.
//Base Class
class Vehicle
{
public void Testvehicle()
{
//TODO:
}
}
//Derived Class
class Car: Vehicle
{
public void testCar()
{
//TODO:
}
}
Multilevel Inheritance:
In multilevel inheritance, there could be one more derived class of derived class. And for the new derived class, this derived class works as the base class or parent class.
//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:
In multiple inheritances, there could be more than one parent class or base class for one derived class or subclass. This derived class will inherit the properties of both the parent classes.
JAVA and DOT NET(C#, F#, etc.) do not support multiple inheritances.
//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:
In multipath inheritance, one derived class can inherit the other two derived classes which are derived from the same base class. See the below image for the same.
JAVA and DOT NET(C#, F#, etc.) do not support multiple inheritances.
//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:
In hierarchical inheritance, there can be more than one derived class that will inherit the single base class or parent class.
//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:
Hybrid inheritance is the combination of multiple and multilevel inheritances as two classes can inherit one parent class and then another derived class can inherit these two derived classes. See the below image for the same.
JAVA and DOT NET(C#, F#, etc.) do not support multiple inheritances.
//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 has many forms, One character has 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 by many names so don’t confuse it with the name, they all are the same as given above in the heading.
In Static Polymorphism, the function with the same name is overloaded with a different parameter or with a different signature.
If we see a 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:
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, and normal water point.
All function working is the same to give water but the output is different. We decide at runtime which type of water we need.
See the image below:
5. OOPS Concepts – Data Abstraction:
It is a schema where essential properties are shown at the front end and the remaining are kept behind the screen.
For example, in in-car making the engine, wiring, and other complex parts are kept hidden or under the bonnet, as the user
does not have to deal with it whereas the steering, dashboard, and meter sound system light are kept outside, in front of the user so that he can use that efficiently.
Another good example is ourselves, As we have all qualities inside us like anger, mood, happiness, sadness, etc.
But we always show our best side or good behavior in front of others until or unless we need to show real feelings.
See the image below:
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 mixed in it.
See the image below:
Please keep reading our blogs for new updates.
Quick Q&A:
What are the 5 OOP principles?
The five principles of oops concepts are given below:
- Single Responsibility Principle.
- Open/Closed principle.
- Liskov Substitution principle.
- Interface Segregation Principle.
- Dependency Inversion principle.
What are the three Oops principles and define them?
The three main principles of oops concepts are Encapsulation, inheritance, and polymorphism. Detailed information on these principles can be found in the blog above.
What are the 3 pillars of OOP?
The three pillars in oops are the same as the three main principles of oops concepts which are given below:
Encapsulation
Inheritance
Polymorphism
Is Python an OOP?
Yes, Python has been an object-oriented language since its discovery.
This makes it easy to create classes and objects in the Python language and easy to learn.
Click here to read the OOPS Concepts in Hindi……
Conclusion:
So here in this blog post(What is the OOPs concept with example) of OOP’s concepts, we have learned what are the 4 basics of OOP..? What is the OOPs concept for example? What are the main features of OOP? What are OOPs in C++? Why are OOPs used? You know Object, Class, Inheritance, Polymorphism, Data Abstraction, and Encapsulation.
OOPs, and concepts are mostly asked questions in either job interviews or in your college viva. And these OOPS concepts build the foundation of your programming language. You can easily make complex and flexible programs in any language if you have a sound knowledge of OOP concepts. Oops, concepts are very popular in technical studies of programs and software building|What is the OOPs concept with example|
We have also gone through What are OOPs concepts, What is the OOPs concept with an example, What are the 4 basic concepts of object-oriented programming, How can I learn OOPs concepts easily, Why are OOPs used, What is polymorphism in OOPs, What is the full form of OOPs, In case of any queries|What is the OOPs concept with example|
you can write to us at A5thoerys@gmail.com we will get back to you ASAP.
Hope! you would have enjoyed this post What is the OOPs concept with an example?
Please feel free to give your important feedback in the comment section below.
Have a great time! Sayonara!