OOP (Object-Oriented Programming )
OOP is a programming style that contains the concepts of classes, Objects, etc. Classes and Objects are the two main aspects in an Object-Oriented Programming language but OOP also conatins some other concepts like Inheritance, Abstraction, Polymorphism, encapsulation which are also very useful.
Except C language almost every modern programming language like C++, JAVA, Python, etc have Object-Oriented Programming style. OOP has several benefits to use in an programming languages like
OOP is a programming style that contains the concepts of classes, Objects, etc. Classes and Objects are the two main aspects in an Object-Oriented Programming language but OOP also conatins some other concepts like Inheritance, Abstraction, Polymorphism, encapsulation which are also very useful.
Why OOP ?
Except C language almost every modern programming language like C++, JAVA, Python, etc have Object-Oriented Programming style. OOP has several benefits to use in an programming languages like
- OOP is easier and faster in terms of executing the program.
- OOP has the concept of Inheritance which can allow us to use existing codes i.e, we don't need to write again the same code which contains almost same properties.
- OOP has helps us to prevent the C++ code DRY (Don't Repeat Yourself) which prevents the code become a mess and is easier to understand by the End-User.
What is Class ?
A Class is the building blocks of a program. It is user-defined datatype i.e, it is defined by the user. basically a Class is the blue-print of an Object.
A Class is the collection of similar type of Objects.
For example:- Lets take an example of a Class➜"CAR". In this class all the cars shares similar properties like "number of wheels", "headlights", "brakes", "car-doors", etc. So here CAR is the Class and those are its properties.
class Class_name{ //class and class_name
public/protected/private : //Any one of the Access Specifier.
datatype variable_name; //data-members & member-function
datatype variable_name; //Datatype can be int, float, string, etc.
:
datatype variable_name;
};
What is an Object ?
An Object is a real-time entity. An Object is an instance of a Class. when a class is defined, no memory is allocated but when it is instantiated (i.e, an Object is created) memory is allocated.
For example:- Lets take an example of a Class➜"CAR". And there are a lots of cars-
A Class is the collection of similar type of Objects.
For example:- Lets take an example of a Class➜"CAR". In this class all the cars shares similar properties like "number of wheels", "headlights", "brakes", "car-doors", etc. So here CAR is the Class and those are its properties.
How to Declare a Class ?To declare a Class, we use the keyword "class"
class Class_name{ //class and class_name
public/protected/private : //Any one of the Access Specifier.
datatype variable_name; //data-members & member-function
datatype variable_name; //Datatype can be int, float, string, etc.
:
datatype variable_name;
};
What is an Object ?
An Object is a real-time entity. An Object is an instance of a Class. when a class is defined, no memory is allocated but when it is instantiated (i.e, an Object is created) memory is allocated.
For example:- Lets take an example of a Class➜"CAR". And there are a lots of cars-
Class | Object |
---|---|
Car | Audi |
Ford | |
BMW |
How to Declare an Object ?
The Object can be declared by writing the name of its class in-front of it.
class Class_name{ //class
public/protected/private : //Access Specifier.
datatype variable_name;
datatype variable_name; //data-members & member-function
:
datatype variable_name;
};
void main( )
{
Class_name Object_name; //create an object of a class.
//To access we use (•) operator.
object_name . variable_name
}
Difference between Procedural and Object-Oriented Programming language.
For giving some suggestion please comment us or check our "Contact us" page. Also more update related to coding will be added in this Blog later on, so please get attached with this Blog by clicking the follow button. Thank you for your support and time...
0 Comments