answersLogoWhite

0


Best Answer

Constructors have no value, zero or otherwise. That is, constructors cannot return a value. This is because constructors are not functions in the sense you cannot call a constructor directly. Constructors are invoked in the background when you instantiate an object of the class, thus any return value would be lost in the background, and would therefore not be visible to the invokee.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a constructor with value zero?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a no args constructor?

No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.


Why is the constructor of the Stack Linked List class empty?

The default constructor of a stack is empty because the default value of any container, including a linked list, is an empty container which requires no arguments (all members default to zero).


A default constructor has how many parameters?

None, zero. Example: new MyClass(); //and public classMyClass{} no constructor defined inside of MyClass


True or False A C plus plus class constructor cannot return a function value?

True - A C++ constructor cannot return a value.


Why there is the need of the constructor if you can assign the value to variables by the help of the methods ..?

A constructor is what allocates memory for an object. If you didn't call a constructor, you would have no object in which to assign values.


What does it mean in java when a constructor is undefined?

When a constructor is not define in java then the instance used in class is not optimised the value and therefore some times it generates some garbage value. By the way , When we not define a constructor then generally it not distrub the execution of the program.


How do you invoke the constructor function in c plus plus?

There is no such thing as a constructor function in C++ (constructors have no return value, not even void, and cannot be called like regular functions). Constructors are invoked rather than called directly, either by declaring a static variable of the class type, or via the C++ new operator.


What is the value of zero?

The value of zero is zero. Zero is always going to have a value of zero.


What enables an object to initialize itself when it is created?

Object initialisation is taken care of by the object's constructor(s). Initialisation is generally done during the initialisation stage of the constructor (immediately before the body of the constructor). Complex members such as pointers can be initialised to NULL in the initialisation stage. If new memory must be allocated to a member pointer, do it in the body of the constructor. Remember to clean up all allocated memory in the class destructor. class cMyClass { public: // Construction. cMyClass(); // Default constructor. cMyClass(const cMyClass & MyClass); // Copy constructor. cMyClass(const int i); // Overloaded constructor. ~cMyClass(); // Destructor. private: // Member variables. int m_int; // An integer. int * m_pInt; // A pointer to an integer. }; // Default constructor. cMyClass::cMyClass(): // Colon indicates initialisation stage. m_int( 0 ), // Comma-separated list of members to be initialised. m_pInt( NULL ) // Optional; m_pInt will be initialised in the body. { // Body of the constructor: // m_int is currently initialised to the value zero. // m_pInt currently points to NULL. m_pInt = new int; *m_pInt = 0; // m_pInt now points to new memory containing the value zero. // Initialisation is complete! } // Copy constructor cMyClass::cMyClass(const cMyClass & MyClass): // Initialisation m_int( MyClass.m_int ), // Member list m_pInt( NULL ) { // m_int is initialised to the value of MyClass.m_int // m_pInt currently points to NULL. m_pInt = new int; // Allocate new memory. *m_pInt = *MyClass.m_pInt; // Deep-copy the value. // m_pInt now points to a copy of the value pointed to by MyClass.m_pInt. // Initialisation is complete! } // Overloaded constructor cMyClass::cMyClass(const int i): // Initialisation. m_int( i ), // Member list. m_pInt( NULL ) { // m_int is initialised to the value of i. // m_pInt currently points to NULL. m_pInt = new int; *m_pInt = 0; // m_pInt now points to new memory containing the value zero. // Initialisation is complete! } // Destructor. cMyClass::~cMyClass() { // Clean up allocated memory. if( m_pInt ) delete m_pInt; }


Does zero have any value?

of course it has - a value of zero - so if something times zero is zero - it must have a value


Why not sending arefrence to copy constructor will cause an infinite loop?

A copy constructor gets called any time an object needs to be copied. Unlike in some of the newer languages like Java, you can chose to pass objects either by reference or by value. When you pass by reference, only the address of the function is copied. However, if you pass by value, the whole object must be copied. In order to copy the object, the copy constructor will get called. If the copy constructor's parameter is not a reference, then the object will get passed by value. When the object gets passed by value, it needs to get copied so it will call the same copy constructor. Because the object is still being passed by value it'll call itself again to create a copy of itself. The copy constructor will continue to call itself until the stack overflows.


Why constructor in Java doesn't have any return type?

The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does. Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.