Object-Oriented Programming in C++
An overview of object-oriented programming in C++.
StartKey Concepts
Review core concepts you need to learn to master this subject
Classes and Objects
Access Specifiers
Constructors
Inheritance
Polymorphism
Class Members
Constructor
Objects
Classes and Objects
Classes and Objects
#include <iostream>
class Dog {
public:
int age;
void sound() {
std::cout << "woof\n";
}
};
int main() {
Dog buddy;
buddy.age = 5;
buddy.sound(); // Outputs: woof
}
A C++ class is a user-defined data type that encapsulates information and behavior about an object.
A class can have two types of class members:
- Attributes, also known as member data, consist of information about an instance of the class.
- Methods, also known as member functions, are functions that can be used with an instance of the class.
An object is an instance of a class and can be created by specifying the class name.
What you'll create
Portfolio projects that showcase your new skills