Data Security Enhancement in Cloud Computing by Proposing a Dke Encryption Protocol
Data Security Enhancement in Cloud Computing by Proposing a Dke Encryption Protocol
• Class
• Access Specifiers/Modifiers
• Object
class class-name {
private data and functions
access-specifier: //Simple Example of class
data and functions
class Student
access-specifier: {
data and functions
public:
// ... int id; //field or data member
float salary; //field or data member
access-specifier:
data and functions String name;//field or data member
};
} object-list;
By default, functions and data declared within a class are private to that class and may be
accessed only by other members of the same class.
The public access specifier allows functions or data to be accessible to other parts of our
program.
The protected access specifier is needed only when inheritance is involved.
type_name variable_name ;
where,
type_name is a class_name
variable_name is an object or list of objects
In this example, Student is the type, and s1 is the reference variable that refers to the instance
of the Student class.
• Types of Constructor
✓ Default Constructor
✓ Parameterized Constructor
✓ Copy Constructor
• Destructor
A constructor will have exact same name as the class and it does not have any return
type at all, not even void.
Constructors can be very useful for setting initial values for certain member variables.
Constructors initialize values to object members after storage is allocated to the object.
While defining a constructor you must remember that the name of constructor will be
same as the name of the class, and constructors will never have a return type.
Object-Oriented Programming| IT Department| Stage-2 2/1/2024 18
Constructors can be defined either inside the class definition or outside class definition
using class name and scope resolution operator (::)
Syntax of defining a constructor in the class A by following two ways:
/*
/*
Constructor Definition outside class A
Constructor Definition inside class A
*/
*/
class A
class A
{
{
public:
public:
int i;
int x ;
A( ); // constructor declared
};
// constructor definition
A( )
// constructor definition
{
A :: A( )
// object initialization
{
}
i = 1;
};
}
Object-Oriented Programming| IT Department| Stage-2 2/1/2024 19
Special characteristics of Constructors
1. Constructor should be declared in the public section.
4. Constructor cannot be inherited though derived class, programmer can call the base
class constructor.
As it is used to create an object, hence it is called a constructor. And, it creates a new object,
which is exact copy of the existing object, hence it is called copy constructor.
/* Copy constructor */
Samplecopyconstructor (const Samplecopyconstructor &sam) cout<<"Normal constructor : ";
{
x = sam.x; obj1.display( );
y = sam.y;
}
cout<<"Copy constructor : ";
void display()
{ obj2.display( );
cout<<x<<" "<<y<<endl; Output
} return 0;
}; Normal constructor : 10 15
} Copy constructor : 10 15
Object-Oriented Programming| IT Department| Stage-2 2/1/2024 26
Destructors in C++
Destructor is used to destroy the class object. Destructor is a special class function, which
destroys the class object, as soon as the scope of object ends.
The destructor is called automatically by the compiler, when the object goes out of scope.
• Types of Inheritance
✓ Single Inheritance
✓ Multiple Inheritance
✓ Hierarchical Inheritance
✓ Multilevel Inheritance
✓ Hybrid Inheritance
And, the class which inherits properties of other class is called Child or Derived or Sub class.
Inheritance makes the code reusable. When a programmer inherits an existing class, all
its methods and fields become available in the new class. Hence, the code is reused.
While defining a subclass like this, the super class must be already defined or at least declared before the subclass
declaration.
Access Mode may be public, private or protected.
Access Mode is used to specify, the mode in which the properties of superclass will be inherited into subclass.
Points to Remember
1. Whether derived class's default constructor is called or parameterized is called, base class's default
constructor is always called inside them.
2. To call base class's parameterized constructor inside derived class's parameterized constructor,
programmer must mention it explicitly (manually) while declaring derived class's parameterized
constructor.
public: public:
Base(int i) // parameterized constructor Derived(int j) : Base(j) // parameterized constructor
{
{
y = j;
x = i;
cout << "Derived Parameterized Constructor\n";
cout << "Base Parameterized Constructor\n";
}
}
};
};
int main()
Output {
Base Parameterized Constructor Derived d(10) ;
Derived Parameterized Constructor }
Object-Oriented Programming| IT Department| Stage-2 2/1/2024 43
Why is Base class Constructor called inside Derived class?
Constructors have a remarkable job of initializing the object correctly. A Derived class constructor has
access only to its class members. However, a Derived class object also has inherited property of the Base
class, and only the base class constructor can properly initialize base class members. Thus all the
constructors are called, and even the base class object would not be well constructed.
}; };
class C : virtual public A
{
// class definition
};
• Types of Polymorphism
• Compile-time Polymorphism
✓ Function Overloading
✓ Operator Overloading
• Runtime Polymorphism
✓ Function Overriding
• Purpose of Polymorphisms
Real life example of polymorphism, a person at the same time can have different
characteristic. Like a man at the same time is a father, a husband, an employee. So the same
person posses different behavior in different situations. This is called polymorphism.
// function with same name and 2 int parameters In this example, a single function named func acts
void func(int x, int y)
{ differently in three different situations, which is the
cout << "value of x and y is " << x << ", " << y << endl;
} property of polymorphism.
};
NOTE: In function or method overriding, the function in parent class is called the overridden
function and function in child class is called overriding function.
In case of function overriding, Programmer have two definitions of the same function, one is in
parent class and another in child class.
The call to the function is determined at runtime to decide, which definition of the function is
to be called, so it is called runtime polymorphism.
Function overriding is a feature that allows the programmer to have a same function in child
class, which is already present in the parent class.
A child class inherits the data members and member functions of parent class, but when
programmer want to override a functionality in the child class, then programmer can use
function overriding. It is like creating a new version of an old function, in the child class.
Object-Oriented Programming| IT Department| Stage-2 2/1/2024 59
Simple Program: Function Overriding in C++
#include <iostream>
using namespace std; int main()
{
class A { //Parent class object
public: A obj;
void disp( ){ obj.disp( );
It is also known as overloading, early binding and static It is also known as overriding, Dynamic binding and late
binding. binding.
Overloading is a compile time polymorphism where more than Overriding is a run time polymorphism where more than one
one method is having the same name but with the different method is having the same name, number of parameters and
number of parameters or the type of the parameters. the type of the parameters.
It provides fast execution as it is known at the compile time. It provides slow execution as it is known at the run time.
✓ Virtual Function
✓ Pure-virtual Function
• Provide the uniform interface of the same actions for the sub-classes.
Different Case 2: If a derived class does not define the virtual function, it will
class D1: public B0 use the same definition of the virtual function as the base class.
{
//No Virtual Function definition
Output:
};
B0::display()
B1::display( )
B0::display()
2. Add a keyword virtual before the function prototype, and cannot be used for the definition outside
the class.
3. Can be inherited, all the functions with the same name in the derived class belong to virtual function.
4. Called be the pointer or reference of the base class, and decided by the pointer to the class.
6. Virtual functions can not be overloaded, they must be defined as the same declarations as in the base
class with or without virtual.
Concrete classes
Classes that can instantiate objects and provide specifications to make real objects.