answersLogoWhite

0


Best Answer

You can have any number of constructors for a class. All we need to do is implement constructor overloading.

Ex: let us say we want to create multiple constructor for a class Test

Public class Test {

Public Test() {

//code

}

Public Test(int vals) {

//code

}

Public Test(String val) {

//code

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Multiple constructors are overloaded versions of the class constructor. They are chosen based on their argument types.

The default constructor takes no arguments.

The copy constructor takes one argument of reference type to a const variable of the class.

The conversion constructor takes one argument of different type than the copy constructor.

Other constructors take two or more arguments and can be used for special initialization. Often, these other constructors can be built as one, using default values for arguments so, for instance, one of them could function as the default constructor if needed.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

To give multiple options of how you can create an object of the current class

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Derive the object from multiple classes.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you call multiple constructors with single object?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a constructor with value zero?

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.


Can you call a constructor from another if a class has multiple constructors?

Yes. All you need to do is to specify the correct number of arguments to invoke the correct constructor.


What are the applications of this pointer?

The this pointer is used to refer to the object that is foremost in the current scope. It has three primary purposes. First, a programmer uses this to refer to a member variable that has been shadowed by a function argument. Secondly, it is used to obtain a reference to itself, usually for the purpose of passing itself to another function or class. Finally, the this pointer can be used to call alternate constructors of the same object, usually as a means of reusing code and providing various constructors with default arguments.


Static method can be call object?

yes we can call a static method with object


How constructor called?

You cannot invoke a constructor explicitly. It will get invoked implicitly when you call the new keyword on the class to create an object of the class. Ex: private ClassExample obj = new ClassExample(); here this new keyword usage on the ClassExample class will invoke the constructor of this class and create an object of that class.

Related questions

What is a constructor with value zero?

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.


Can you call a constructor from another if a class has multiple constructors?

Yes. All you need to do is to specify the correct number of arguments to invoke the correct constructor.


What do you call the combination of variables and functions into a single object in C plus plus?

A singleton.


Is CAll of duty classic on PS3 for single or multiple players?

yes it is for single player offline and multiplayer online if by classic you mean Call of Duty 3 see related link


What are the applications of the pointer?

The this pointer is used to refer to the object that is foremost in the current scope. It has three primary purposes. First, a programmer uses this to refer to a member variable that has been shadowed by a function argument. Secondly, it is used to obtain a reference to itself, usually for the purpose of passing itself to another function or class. Finally, the this pointer can be used to call alternate constructors of the same object, usually as a means of reusing code and providing various constructors with default arguments.


Can you use multiple controllers on wii with mw3?

No, Call of Duty: Modern Warfare 3 for Wii is single player.


What are the applications of this pointer?

The this pointer is used to refer to the object that is foremost in the current scope. It has three primary purposes. First, a programmer uses this to refer to a member variable that has been shadowed by a function argument. Secondly, it is used to obtain a reference to itself, usually for the purpose of passing itself to another function or class. Finally, the this pointer can be used to call alternate constructors of the same object, usually as a means of reusing code and providing various constructors with default arguments.


Is Skype social networking site or a virtual classroom?

On skype, you are able to message people of your choice, call a single person or multiple people, and even video chat one or multiple people.


What is the method of calling object's constructor in a function?

A constructor is not a function (it has no return value, not even void). As such you cannot call a constructor as you would a function. Constructors are always invoked automatically whenever an object of the class is instantiated. For example: struct S { // ...class has implicit default constructor }; static S s1; // instantiate an object of type S in static memory void f () { S s2; // instantiate an object of type S on the call stack } // s2 falls from scope here void g() { S* p = new S; // instantiate an object of type S on the heap // ... delete p; // release the object pointed to by p } // p falls from scope here int main() { f(); // call function f g(); // call function g } // s1 falls from scope here


Can multiple IP PBX share multiple call processors?

Multiple IP PBX can share multiple call processors with the use of standard interface.


What do you call the measurement of the gravitatonal force acting on an object?

You call that the "weight" of the object.


Static method can be call object?

yes we can call a static method with object