Q. What is Object-Oriented Programming? And Basic Concept of OOP.
Answer:-
- Object-Oriented Programming is a programming in which we design and develop our application or program based on Object. Objects are instances(Variables) of class.
- Object-Oriented Programming does not allow data to flow freely around the system. It binds data more closely to the functions from outside Functions.
Basic Concept of OOP
1) Class:-
- Class are an expanded version of structures. Structure can contain multiple Variables.
- Classes can contain multiple variables even more Classes can also contain Function as class member.
- Variables available in class are called Data Members.
- Functions available in class are called Member Functions.
2) Object:-
- Class is a user-defined data type and object is a variable of class type.
- Object is used to access class members.
Example of class & object:-
class myclass{ //The class
public: //Access specifire
int myNum; //Attribute (int variable)
string myString; // Attribute (String varibable)
};
int main(){
myclass myobj; //Create an object of my class
//Access attributes and set values
myobj.myNum=15;
myobj.myString="some text";
}
3) Inheritance:-
- Inheritance means access the properties and features of one class into another class.
-The class who is going to provide its feature to another class will be called base class and the class who is using the properties and features of another class will be called derived class.
4) Polymorphism:-
- Polymorphism means more than one function with same name with different working .It can be static or dynamic.
-In static polymorphism memory will be allocated at compile time. In dynamic polymorphism memory will be allocate at run time.
-Both Function overloading and operator overloading are an examples of static polymorphism.
-Virtual Function is an example of dynamic polymorphism.
5) Data Abstraction:-
- The basic idea of data abstraction is to visible only the necessary information, unnecessary information will be hidden from the outside the world.
- This can be done by making class members as private members of class.
- Private members can be accessed only within the same class where they are declared.
6) Encapsulation:-
- Encapsulation is a process of wrapping data members and member functions in single unit called class.
- Using the method of encapsulation the programmer cannot directly access the data.
-Data is only accessible through the object of the class.
Thanks for reading....
0 Comments