- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
- C++ Advanced
- C++ Files and Streams
- C++ Exception Handling
- C++ Dynamic Memory
- C++ Namespaces
- C++ Templates
- C++ Preprocessor
- C++ Signal Handling
- C++ Multithreading
- C++ Web Programming
How to start object-oriented programming in C++?
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of attributes; and instructions to do things, in the form of methods.
For example, a person is an object which has certain properties such as height, gender, age, etc. It also has certain methods such as move, talk, and so on.
This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.
When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.
OOP has four basic concepts on which it is totally based. Let's have a look at them individually −
- Abstraction − Abstraction means providing only essential information to the outside world and hiding their background details. For example, a web server hides how it processes data it recieves, the end user just hits the end points and gets the data back.
- Encapsulation − Encapsulation is a process of binding data members (variables, properties) and member functions (methods) into a single unit. It is also a way of restricting access to certain properties.
- Inheritence − The ability of creating a new class from an existing class is called Inheritence. Using inheritence, we can create a Child class from a Parent class such that it inherits the properties and methods of the parent class and can have its own additional properties and methods. For example, if we have a class Vehicle that has properties like Color, Price, etc, we can create 2 classes like Bike and Car from it that have those 2 properties and additional properties that are specialized for them like a car has numberOfWindows while a bike cannot. Same is applicable to methods.
- Polymorphism − The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. For example, if we have a class called Shape and a method called getArea in it, then depending on what the shape is, we'll be getting the area processed in a different way(Circle vs square).
You can head over to the excellent tutorial on C++ Object oriented programming on tutorials
point(https://www.tutorialspoint.com/cplusplus/cpp_object_oriented.htm) to start learning OOP.
- Related Articles
- Object-oriented programming in Swift
- Object Oriented Programming in Python?
- Object-Oriented Programming in R
- Basic Concepts of Object Oriented Programming using C++
- Object Oriented language v/s Procedure oriented programming language.
- What is object-oriented programming (OOP)?
- Python Object-oriented and Functional Programming
- 8 Tips For Object-Oriented Programming in Python
- What is the difference between Object oriented programming and Object based programming?
- What are basic Object oriented programming concepts?
- Differences between Procedural and Object Oriented Programming
- Object Oriented language v/s Object based programming language.
- What is Data Hiding in Python Object Oriented Programming?
- What does the repr() function do in Python Object Oriented Programming?