Why c++ called as an object oriented programming language ?

01 Mar 2022 Balmiki Mandal 0 C++

Reasion Object-Oriented Programming Language

C++ is called an object-oriented programming language because it supports the following key features of object-oriented programming:
  • Objects: C++ allows you to create objects, which are self-contained units of code that contain both data and behavior.
  • Classes: Classes are blueprints for creating objects. Classes define the data and behavior that objects will have.
  • Inheritance: Inheritance allows you to create new classes that inherit the data and behavior of existing classes. This makes it easier to develop new features and functionality.
  • Polymorphism: Polymorphism allows objects to behave in different ways depending on their type. This makes code more flexible and reusable.

C++ also provides a number of other features that are useful for object-oriented programming, such as encapsulation, data abstraction, and dynamic binding.

While C++ supports object-oriented programming, it is also a multi-paradigm language, which means that it also supports other programming paradigms, such as procedural programming and generic programming. This makes C++ a very versatile language that can be used to develop a wide variety of applications.

Example of an object-oriented program in C++:

C++
class Person {
public:
  Person(std::string name, int age) : name(name), age(age) {}

  std::string getName() const { return name; }
  int getAge() const { return age; }

private:
  std::string name;
  int age;
};

int main() {
  Person person("Alice", 25);

  std::cout << "Hello! My name is " << person.getName() << std::endl;
  std::cout << "I am " << person.getAge() << " years old." << std::endl;

  return 0;
}

The output of the program is:

 

Hello! My name is Alice
I am 25 years old.

This program creates a new Person object with the name "Alice" and the age 25. Then, the program calls the getName() and getAge() methods on the Person object to print the person's name and age to the console.

C++ is a powerful and versatile language that is well-suited for object-oriented programming. It is widely used in a variety of industries, including game development, embedded systems, and scientific computing.

Further Reading:

For further information and examples, Please visit[ course in production]

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.