answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2013-04-10 18:26:03

This is when you overload the constructor so that there isn't just one way you can initialize the class object

Assume you have a class called Foo and you want two different constructors


Foo(int a, int b);

Foo(float a, float b);


using a method like this can make your classes more dynamic and you don't need to to write a new class to handle different types. Sorry for the lack of Java code, i program in C++ but it you can overload functions and constructors in C++ too.

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Related Questions


really there is no difference between constructor overloading and metho overloading


how many constructer can be defined in class in overloading of java programming


this in java is a keyword that refers to the current object of the class. It is also used in constructor overloading when you want to invoke one constructor from another within the same class.


I think constructor overloading is the concept of polymorphism.


When we are initializing our object with different internal state then we can use the constructor overloading.


yes,because in constructor overloading constructor have same and different parameter list. In method overloading method have same name and different parameter list.



Overloading a constructor means typing in multiple versions of the constructor, each having a different argument list, like the following examples: class Car { Car() { } Car(String s) { } } The preceding Car class has two overloaded constructors, one that takes a string, and one with no arguments


The first thing to note about constructor overloading is that Java creates a no argument constructor for you if and only if you have not typed a constructor yourself. Every class has a constructor even abstract ones (default no argument constructor). Abstract constructors are always executed. To overload a constructor you can do the following: class Test { String name; Test(String n) { name = n; System.out.println("Constructing Test Object named: " + name); } } In the case above we are overloading the default no argument constructor with a constructor that takes a String parameter. You can write you own no argument constructor as follows: class Test { Test() { System.out.println("Constructing Test Object"); } } To override our own no argument constructor we do this: class Test { Test() { // our no argument constructor System.out.println("Constructing Test Object"); } String name; Test(String n) { // overloading our no argument constructor with this // constructor that take a String parameter name = n; System.out.println("Constructing Test Object named: " + name); } }


Operator overloading is not possible in Java.


No. Java does not support copy constructor


Constructor overloading, just like any function's overloading, is where more than one configuration of parameters exists for the function. Based on the number and type of the parameters, different versions of the function can be resolved by the linker. This is typically used in the constructor as the default constructor (no parameters), the copy constructor (one reference parameter of the same type as the class), and the conversion constructor (any other combination of parameters).


Operator overloading refers to redefining what the mathematical operators (+-*/) do when applied to different objects. Java does not support operator overloading.


Like methods, constructors can also be overloaded. Since the constructors in a class all have the same name as the class, their signatures are differentiated by their parameters lists


When the programmer has not coded a constructor for any java class.


When any constructor is deffined in your class, the java compiler create a default no argument constructor for you. This constructor only have an invocation to the super class constructor (" super( ) ").


All Java programs would have a constructor... public class Test { public Test(){ ... } ..... } This is a constructor. Even if you dont code the constructor Java would automatically place a default constructor for compilation.


A constructor is just a special form of a method. You can overload constructors in the exact same way as you can overload any other method.


What are the importance of constructor in java? Constructor is automatically called immediately after the object is created , before the new operator complete . Constructor is important because they have no return type , not even void.


No. The constructor is the starting point of creation of any object in Java. Without going through a constructor you cannot create an object


Overloading a constructor means typing in multiple versions of the constructor, each having a different argument list, like the following examples: class Car { Car() { } Car(String s) { } } The preceding Car class has two overloaded constructors, one that takes a string, and one with no arguments. Because there's no code in the no-arg version, it's actually identical to the default constructor the compiler supplies, but remember-since there's already a constructor in this class (the one that takes a string), the compiler won't supply a default constructor. If you want a no-arg constructor to overload the with-args version you already have, you're going to have to type it yourself, just as in the Car example. Overloading a constructor is typically used to provide alternate ways for clients to instantiate objects of your class.


Constructor is used to do something (written in constructor) immediately after object creation.


Default Constructor Parameterised Constructor Non Parameterised Constructor


In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.




Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.