Web viewWrite a short note on significance of constructors in OOP classes ... GType and GFabric with...

download Web viewWrite a short note on significance of constructors in OOP classes ... GType and GFabric with the word "NOT ALLOTTED" and GSize and GPrice with O

If you can't read please download the document

Transcript of Web viewWrite a short note on significance of constructors in OOP classes ... GType and GFabric with...

Constructors & Destructors

Write a short note on significance of constructors in OOP classes

'Only a function that has access to the constructor and destructor of a class, can use the objects of this class'. Comment on this statement.

Write 4 characteristics of a constructor function used in a class

What do you understand by a default constructor ? What having default arguments ?

What do you mean by a temporary instance of a class ? What is its use ? How is it created ?

Distinguish between the following two statements :

time T1 (13, 10, 25);//statement 1

time T1 = time (13, 10, 25);//statement 2

Discuss the various situations when a copy constructor is automatically invoked. SOLUTION. Generally, in the following three situations, a copy constructor is invoked :

1. When an object is defined and initialized with another object of the same type, then the copy constructor is invoked to copy the data values of one object to the other.

2. When an object is passed by value to a function, then the copy of the passed object is created for the function by invoking the copy constructor.

3. When a function returns an object, the copy constructor creates a temporary object to hold the return value of the function returning an object.

Write a short note on the significance of the destructors

Differentiate between Constructor and Destructor function with respect to Object Oriented Programming.

When a compiler can automatically generate a constructor if it is not defined then why is it considered that writing constructors for a class is a good practice ?

'Accessibility of a constructor or a destructor greatly affects the scope and visibility of their class.' Elaborate this statement.

Explain the role of a default constructor ? When is it considered equivalent to a parameterized constructor ? Support your answer with examples.

List some of the special properties of the constructor functions.

Write any two similarities between Constructors and Destructors. Write the function headers for constructor and destructor of a class Flight.

What is a parameterized constructor ? How is it useful ?

What is a copy constructor ? at is its significance ? Which situations is it invoked in ? Support your answer with examples.

Differentiate between a default constructor and copy constructor, giving suitable examples of each.(Outside

Describe the importance of destructors. List some of the special properties of destructors.

Answer the questions (i) and (ii) after going through the following class :(

class TEST {

int Regno, Max, Min, Score ;

public :

TEST()//Function 1

{Regno = 101 ; Max = 100 ; Min = 4

0;Score =75; }

//Function 2

40 ; Score = Pscore ;

//Function 3

//Function 4

TEST(int Pregno, int Pscore)

{

Regno = Pregno ; Max = 100 ; Min =

}

"TEST( )

{

cout