0% found this document useful (0 votes)
18 views

Object Oriented Programming

Static members and methods in C++ allow sharing of data between class objects. Encapsulation binds data and functions that manipulate the data within a single unit. Constructors initialize objects and are automatically called when objects are created. Destructors free memory allocated by constructors and are automatically called when objects go out of scope.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Object Oriented Programming

Static members and methods in C++ allow sharing of data between class objects. Encapsulation binds data and functions that manipulate the data within a single unit. Constructors initialize objects and are automatically called when objects are created. Destructors free memory allocated by constructors and are automatically called when objects go out of scope.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Object Oriented Programming

Abdul Mateen
Lecture 03
Static Member & Static Methods in C++

What is Static Member in C++?


 When a static data member is created, there is only a single
copy of the data member which is shared between all the
objects of the class.

What is Static Method in C++?


 Static methods can only access static data members and
static methods. Static methods can only be accessed using
the scope resolution operator.
Encapsulation in C++

What is Encapsulation in C++?


 Encapsulation is defined as wrapping up of data and
information under a single unit.
 In Object Oriented Programming, Encapsulation is defined
as binding together the data and the functions that
manipulates them.
 Encapsulation also lead to data abstraction or hiding.
Constructor in C++

What is constructor in C++?


 Constructor is a special member function with same
name as class.
 It is used to initialize the objects(private properties) of
its class
 It will automatically call or invoked when ever we create
the object of that class
 It do not return any value
 Constructor have do not need any return type
 It will be declared in the public section
 It may accept parameter and argument
 If it accept no parameter it is called default constructor
 Note: c plus plus references header file function
Constructor in C++

What is constructor overloading in C++?


 In C++, We can have more than one constructor in a
class with same name, as long as each has a different
list of arguments. This concept is known as
Constructor Overloading and is quite similar to
function overloading.
Constructor in C++

What is copy constructor in C++?


 Copy constructor is a type of constructor which create
copy of an object
Destructor in C++

What is copy Destructor in C++?


 A destructor is a member function that is invoked
automatically when the object goes out of scope or is
explicitly destroyed by a call to delete . A destructor has
the same name as the class, preceded by a tilde ( ~ ).
 Destructor can not take a return type and parameters
 Destructor are used to free the memory allocated by
constructor
Destructor in C++

Properties of Destructor:
 Destructor function is automatically invoked when the
objects are destroyed.
 It cannot be declared static or const.
 The destructor does not have arguments.
 It has no return type not even void.
 An object of a class with a Destructor cannot become a
member of the union.
 A destructor should be declared in the public section of the
class.
 The programmer cannot access the address of destructor.
Destructor in C++

When Destructor Call: 

A destructor function is called automatically when the


object goes out of scope: 
(1) the function ends 
(2) the program ends 
(3) a block containing local variables ends 
10
Algorithm Of Success
While(noSuccess) {
tryAgain();
If(Dead) {
Break;
}
}

11

You might also like