What are the various OOPs concepts in C++?

The various OOPS concepts in C++ are:

C++ Interview Questions
  • Class:

The class is a user-defined data type which defines its properties and its functions. For example, Human being is a class. The body parts of a human being are its properties, and the actions performed by the body parts are known as functions. The class does not occupy any memory space. Therefore, we can say that the class is the only logical representation of the data.

The syntax of declaring the class:

  1. class student  
  2. {  
  3. //data members;  
  4. //Member functions  
  5. }  
  • Object:

An object is a run-time entity. An object is the instance of the class. An object can represent a person, place or any other item. An object can operate on both data members and member functions. The class does not occupy any memory space. When an object is created using a new keyword, then space is allocated for the variable in a heap, and the starting address is stored in the stack memory. When an object is created without a new keyword, then space is not allocated in the heap memory, and the object contains the null value in the stack.

  1. class Student  
  2. {  
  3. //data members;  
  4. //Member functions  
  5. }  

The syntax for declaring the object:

  1. Student s = new Student();  
  • Inheritance:

Inheritance provides reusability. Reusability means that one can use the functionalities of the existing class. It eliminates the redundancy of code. Inheritance is a technique of deriving a new class from the old class. The old class is known as the base class, and the new class is known as derived class.

Syntax

  1. class derived_class :: visibility-mode base_class;   

Note: The visibility-mode can be public, private, protected.

  • Encapsulation:

Encapsulation is a technique of wrapping the data members and member functions in a single unit. It binds the data within a class, and no outside method can access the data. If the data member is private, then the member function can only access the data.

  • Abstraction:

Abstraction is a technique of showing only essential details without representing the implementation details. If the members are defined with a public keyword, then the members are accessible outside also. If the members are defined with a private keyword, then the members are not accessible by the outside methods.

  • Data binding:

Data binding is a process of binding the application UI and business logic. Any change made in the business logic will reflect directly to the application UI.

  • Polymorphism:

Polymorphism means multiple forms. Polymorphism means having more than one function with the same name but with different functionalities. Polymorphism is of two types:

  1. Static polymorphism is also known as early binding.
  2. Dynamic polymorphism is also known as late binding.