In programming, a class is a fundamental concept in object-oriented programming languages. A class is a blueprint or template that defines the structure, behavior, and attributes of a particular type of object. It encapsulates data (variables, called attributes or properties) and functions (methods) that operate on the data.
Info |
---|
An object is an instance of a class, created from the class blueprint. Each object can have its own unique set of data and can use the methods defined in the class. Classes promote modularity, reusability, and maintainability in software development. |
Class Members:
Methods
Methods define what an object can do or the behavior of the object.
Constructors
Constructors don’t actually construct the object. The class makes the object and then executes a constructor to initialize the values of the fields (instance variables).
Member Access Specifiers
The members of a class are classified into three categories: private, public, and protected. In C++, private, protected, and public are reserved words and are called member access specifiers.
Following are some facts about public and private members of a class:
By default, all members of a class are private.
If a member of a class is private, you cannot access it directly from outside of the class.
A public member is accessible outside of the class.
To make a member of a class public, you use the member access specifier public with a colon, :
In object-oriented programming, public, private, and protected are access modifiers used to specify the accessibility of class members, such as properties and methods. These access modifiers define the level of access to a class member from outside the class.
Info |
---|
|
Encapsulation
There are two views of an object:
internal - the details of the variables and methods of the class that defines it
external - the services that an object provides and how the object interacts with the rest of the system
From the external view, an object is an encapsulated entity, providing a set of specific services
These services define the interface to the object