- Which of the following is NOT TRUE about constructors and destructors?
- They must the same names as class.
They cannot return values.
- They can be invoked only once in a program.
- They are called automatically.
- Which one of the following statements does not correctly describe one of the many characteristics of constructors?
- They can be inherited.
- They can have default arguments.
- They can not return values, like other functions.
- They can be declared anywhere in the class.
- A constructor for the class Area having two data members length and breadth is declared as follows:
Area (int length = 15, int breadth = 10); Which one of the following object declarations is illegal?
- Area A(20, 10);
- Area A();
- Area A = Area (20, 10);
- Area A;
- Which one of the following is an implicit constructor for the class ROOM having a data member area?
Room ( ) { }
- Room (int a) {area = a}
- Room (Room & a) {area = a.area}
- None of the above
- Which one of the following declarations represents the legal copy constructor for the class X?
X (X);
- X (&X);
- X (X&);
- X ( );
- Identify error, if any, in the following code segment:
- class Sample
- {
- int m;
- Sample ( );
- Sample (int);
- };
- Line 6 should not have semicolon
- In line 5 parameter name is missing
In line 4, argument should be of type void
- Constructors should be declared in public section
Which one of the following is TRUE about a copy constructor?
- It is used for passing address of data members
- It declares and initializes an object from another object
- It is invoked automatically when an object the class is declared
- We can pass the argument by value to it
- Which of the following statements is TRUE?
- A class can have only one constructor
- A constructor must be declared for each class
A default constructor can only be supplied by the compiler
- A constructor is automatically called each time an object is created
- Which of the following statements is TRUE?
A destructor must be declare for each class
- A class can have only one destructor
- A destructor can have default arguments
- Destructors are not useful when the class contains pointer data members
- Which of the following statements is FALSE?
A class can have only default constructor
- A default constructor can only be supplied by the compiler
- A default constructor may be declared without any parameters
- All parameters of a default constructor can have default values
Answers:
- They can be invoked only once in a program.
- They can be declared anywhere in the class.
- Area A();
- Room (int a) {area = a}
- X (&X);
- Constructors should be declared in public section
- It is used for passing address of data members
- A constructor is automatically called each time an object is created
- A class can have only one destructor
- A default constructor can only be supplied by the compiler
You must log in to post a comment.