Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Online Practice Test
>
CPP 2
« Previous
Next »
if constructor is not declared, the compiler assumes the class to have a default constructor with no arguments
Options
- True
- False
CORRECT ANSWER : True
Discussion Board
C++ - Constructors
The above answer is true. Every class has at least one constructor. If you do not mention or write a constructor for a class, C++ generates one constructor for you which is known as Default constructor. It is not visible in your code, but it is available there.
Prajakta Pandit 01-24-2017 04:21 AM
Default constructor
Based on the wording of the statement, that the compiler "assumes the class to have a default constructor", I'd say that the answer should be false.
Generally, when one "assumes" something to be or not, they ignore the thing and move on. The compiler makes no "assumptions" when it comes to a default constructor. It will create one if the programmer hasn't.
From cppreference.com…
"If no user-defined constructors of any kind are provided for a class type (struct, class, or union), the compiler will always declare a default constructor as an inline public member of its class.
"If the implicitly-declared default constructor is not deleted or trivial, it is defined (that is, a function body is generated and compiled) by the compiler, and it has exactly the same effect as a user-defined constructor with empty body and empty initializer list. That is, it calls the default constructors of the bases and of the non-static members of this class.
gds 06-12-2014 06:41 AM
« Previous
Next »
Write your comments
*
*
Email must be in the form someone@domain.com
*
*
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
Related Content
C test (42)
C (12)
C++ for beginners (10)
C++ (20)
C++ (24)
C++ (18)
C++ (14)
C++ (12)
C++ (15)
C++ (15)
Data structure (20)
Data structure (10)
Data structure (10)
Data structure (10)
PERL (25)
VC++ (11)
Oops (30)
Mainframe (41)
Mainframe (15)
Embedded systems (15)
OOAD (49)
Advertisement
▲