Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

Mention three types of constructors.

Answer»

The three types of constructors are:

  1. Default constructor
  2. Parameterized constructor
  3. Copy constructor
2.

How many types of constructors are there?

Answer»

There are three types of constructors.

3.

Why are constructors needed in a program? Justify.

Answer»

The objects are not automatically initialized when created. The explicit call to initialization member function can only initialize the object. This method proves to be inconvenient when large number of objects need to be initialized by giving separate function call. This problem can be overcome by automatically initializing object when they are created using constructor.

4.

Explain the features of copy constructor.

Answer»

The features of copy constructor are:

1. The copy constructor should have at least one argument of the same class and this argument must be passed as a constant reference type.

2. If additional arguments are present in the copy constructor, then it must contain default arguments.

3. Explicit function call of copy constructor is not allowed.

4. Copy constructor is also called automatically, when an object is passed to a function using pass by value.

5. If a new object is declared and existing object is passed as a parameter to it in the declaration itself, then also the copy constructor is invoked.

5.

What is a copy constructor?

Answer»

It is a parameterized constructor using which one object can be copied into another object.

6.

Can a copy constructor be invoked explicitly?

Answer»

No, a copy constructor cannot be invoked explicitly.

7.

Write the syntax for declaration of copy constructor.

Answer»

The syntax for declaration of copy constructor:
Classname :: Classname (Classname &ptr)

8.

When is copy constructor used in a program?

Answer»

The copy constructor takes an object as argument and is used to copy values of data members of one object into other object.

9.

Write the rules for writing a constructor function.

Answer»

The rules for writing a constructor functions are

  • They should be declared in the public section.
  • They are invoked automatically when the objects are created.
  • They should not have return types, therefore they cannot return values.
  • They cannot be inherited.
  • They can have default arguments.
  • Cannot refer to addresses.
  • These cannot be static.
  • An object of a class with a constructor cannot be used as a member of a union.
10.

Name two methods through which constructors can be invoked.

Answer»

The two methods through which constructors can be invoked are implicit call and explicit call.

11.

What is a parameterized constructor?

Answer»

A constructor that takes one or more arguments is called a parameterized constructor.

12.

Write any one feature of parameterized constructor.

Answer»

The parameterized constructor can be overloaded.

13.

What is the drawback of default constructor?

Answer»

All objects of a class with default constructor are initialized to same set of values.

14.

What is a default constructor?

Answer»

A constructor which does not take any arguments is called a zero argument constructor.

15.

Which operator is used with destructor?

Answer»

The operator tilde sign (~) is used with destructor.

16.

What is a destructor?

Answer»

It is a special member function that destroys the objects that have been created by a constructor, when they no longer required.

17.

When is = used with constructors?

Answer»

The = is used for the parameterized constructor with exactly one argument.

18.

What is an implicit call with reference to constructors?

Answer»

In this method, the declaration of object is followed by the argument list enclosed within parentheses.

19.

What is an explicit call?

Answer»

It is a method of invoking a function where the declaration of object is followed by assignment operator followed by a constructor followed by argument list enclosed within parentheses.

20.

What is meant by constructor overloading?

Answer»

If many constructors differ by number of arguments or/and by type of arguments in a class is called constructor overloading.

21.

What is a constructor?

Answer»

It is a special member function that is used to initialize the data members of an object.

22.

What are the features of default constructors?

Answer»

The features of default constructors are

  • All objects of a class are initialized to same set of values
  • These constructors has no arguments
  • These constructors are automatically called when every object is created.
23.

Write short note for constructor overloading.

Answer»

The main use of constructors is to initialize objects. The function of initialization is automatically carried out by the use of a special member function called a constructor. The constructors are no different from other functions. Therefore constructors can also be overloaded.

Overloading a constructor means having many constructors in a class with different types arguments and/or different number of arguments. The compiler decides which version of the constructor to invoke during object creation based on number of arguments and type of arguments passed in a program.

24.

Write one reason which defines the need to use a constructor.

Answer»

The constructors are used to initialize the object automatically when an object is created. This reduces a separate function call to a member function used for such purpose. It is called constructor because it constructs the values of data members of the class.

25.

Can a constructor return a value to a calling function?

Answer»

No, constructors cannot return value to a calling function.

26.

Which are the different methods through which constructors are invoked?

Answer»

The different methods through which constructors are invoked are

  • Explicit call
  • Implicit call
  • Using = operator
27.

What are the disadvantages of default constructor?

Answer»

The disadvantages of default constructor are:

  • Different objects cannot be initialized with different values.
  • Declaring a constructor with arguments, hides default constructor.
28.

Mention the features of parameterized constructors.

Answer»

The features of parameterized constructors are:

  1. parameterized constructors can be overloaded
  2. parameterized constructors can have default arguments and default values.
29.

What should be the access parameters for constructor declaration?

Answer»

The constructors should be declared in public section i.e., public is the access parameter for constructor declaration.

Previous Next