Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following is true about constructors in C++ ?

  • A.Constructors can return values
  • B.A constructor has the same name as the class
  • C.Constructors must have parameters
  • D.Constructors can be invoked explicitly

Answer: B

The true statement is A constructor has the same name as the class.

A C++ constructor is a member function with the same name as its class, called automatically when an object is created, to initialise it.

Constructors have no return type and cannot return values. They need not have parameters (a default constructor has none). A constructor is normally called automatically when an object is created; whatever one makes of explicit calls such as ClassName(args), the defining property the key asks for is the shared name.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.