You are on page 1of 4

Private:

When the private keyword is used to define a function or class, it becomes private. Such are only
accessible from within the class.
Public:
The public keyword, on the other hand, makes data/functions public. These are accessible from
outside the class.
Object Definition:
Objects are created from classes. Class objects are declared in a similar way as variables are
declared. The class name must start, followed by the object name. The object of the class type.

can access any member by dot operator like struct

A constructor is called whenever an object is created and declaration is nothing


but creation of an object.
A constructor is special method function called automatically when an object is
created.

A Destructors  is called whenever lifetime is ended (lifetime of constructor)


-Destructors used to deleted memory located by constructor.

A Destructors  is special method function called automatically when an object


lifetime is ended. (~).
Destructor has the same name as the constructor and it is preceded by ______ .

A) ~ B) ! c)& D) $

For automatic objects, constructors and destructors are called each time the objects ……..
1) enter and leave scope

2)inherit parent class

3)are constructed
4)are destroyed

-A function with the same name as the class, but preceded with a tilde character (~) is called
destructor of that class.

-Which of the following gets called when an object goes out of scope? Destructor

-A class's Destructor is called when an object is destroyed.


How many times a constructor is called in the life-time of an object?

1-Only once 2)Two times 3)three times 4)Four times

Which of the following gets called when an object is being created? Constructor

Which of the following statement is correct about constructors?


1)A constructor has no return type.

2)A constructor cannot contain a function call.

3)A constructor has a void return type.

-Can a class have virtual destructor? YES

-Which of the following statement is correct?

Constructor has the same name as that of the class.


Destructor has the same name as that of the class with a tilde symbol at the beginning.
Both A and B.

-A destructor takes __________ arguments.

One two zero

Q- Find output
int n=5 ;
while (n>0)
{
cout << n << ", ";
--n;
}
cout << "FIRE!\n";

5, 4, 3, 2, 1, Fire!
Q- Find output

int n=5;
do {
cout << n << ", ";
--n;
} while (n<0);
cout << "FIRE!\n";

5 ,Fire!

Q- Chose correct
int arr[5]=10},13,14,20,19{;
int avg , sum=0;
for (int i=0; i<5 ; i++)
}
sum+=arr[i];
{
avg=sum/5;
cout<<avg;

1) 15 2)16 3)17 4) None

Q- Chose correct
int arr[5]=10},13,14,20,19{;
float avg , sum=0;
for (int i=0; i<5 ; i++)
}
sum+=arr[i];
{
avg=sum/5;
cout<<avg;

1)15 2)16 3)17 4) None

Notes :

String : a sequence of zero or more characters enclosed in double quote marks


• C++ strings are null terminated (‘\0’)
• The last character in a string is the null character
There is a difference between 'A' and "A"
'A' is the character A
"A" is the string A
int Func(int &x); //call by reference
int Func(int x); //call by value
unsigned - only positive numbers
signed  positive or negative numbers
unsigned int -> only positive int numbers

You might also like