Python Classes Objects
Encapsulation, information hiding, abstract data types, object and classes, attributes method, C++ class declaration, state idendity and behaviour of an object, Constructors and destructors instantiation of objects, Default parameter value object types, C++ garbage collection, dynamic memoty allocation, Metaclass abstract classes.
Concept of Class -
The mechanism that allows you to combine data and the function in a single unit is called a class. Once a class is defined, you can declare variables of that type. A class variable is called object or instance. In other words, a class would be the data type, and an object would be the variable. Classes are generally declared using the keyword class, with the following format:
class class_name
{
private:
members 1;
projected:
members 2;
public:
members 3;
};
Class
Datas
data 1
data 2
..........
data n
Functions
function ( ) 1
function ( ) 2
.............. ... ..
function ( ) n
A class is a blueprint for objects
When a class is defined, no memory is allocated.
The members of a class are classified into three categories:
private, public, and projected. private, projected, and public are reserved words and are called member access specifiers. These specifiers modify the access rights that the members following them acquire
Private members of a class are accessible only from within other members of the same class. You cannot access it outside of the class.
Protected members are accessible from members of their same class and also from members of their derived classes.
Public members are accessible from anywhere the object is visible.
Example:-
class Circle
{
private:
double radius;
public:
void set Radius(double r)
{
radius = r;
}
double get Area ( )
{
return 3.14 * radius * radius;
}
};
Concept of Object -
An object doesn't exist until an instance of the class has been created; the class is just a definition. When the object is physically created, space for that object is allocated in RAM . It is possible to have multiple objects created from one class.
Encapsulation -
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside inheritance and misuse. Data encapsulation led to the important OOP concept of data hiding .
Data encapsulation is a mechanism of building the data, and the functions that use them and data abstraction is a mechanism of exposing only the inheritance and hiding the implementation details from the user.
Post a Comment