answersLogoWhite

0


Best Answer

You can overload instance methods and constructors (ref. Prog. Logic)

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: An instance method or constructor may be overloaded by providing the same name and arrgument list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which situation constructor is used?

Constructor is necessary when you are about to use instance of a class.


Can you override the constructor?

A constructor should be overloaded when there is a parameter with default value that is commonly used, or if it is possible that not all the information for creating the instance will be gathered all at once. As an example, say there is a class that describes bank accounts. Assuming I can choose to deposit or not deposit money under my name upon creating an account, there is a chance for a meaningful overload. One constructor could take in the name of the account owner and the initial balance as parameters; the overloaded constructor could just take the name as a parameter while setting the initial balance to zero.


Need of constructor in c plus plus?

There is no specific keyword for a constructor in C++. Simply define and declare a method of the class with the same name as the class and it will be a constructor. A constructor with no arguments is the default constructor, a constructor with one argument of class type is the copy constructor, and a constructor with one argument of some other type is the conversion constructor. You can provide other overloaded constructors if you want.


What is difference constructor and function in programming C plus plus?

A Constructor is called when you are making a new instance of a class and member functions are functions that you can call within your class or else call using the instance of that class.for exampleclass Foo {public:int bar;Foo(int bar) {this->bar = bar;}inc_bar(); {this->bar++;}};Foo instance(10); // Constructor is called and bar is set to 10cout


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.

Related questions

Which situation constructor is used?

Constructor is necessary when you are about to use instance of a class.


Use of constructor?

to create an instance of object


Can you override the constructor?

A constructor should be overloaded when there is a parameter with default value that is commonly used, or if it is possible that not all the information for creating the instance will be gathered all at once. As an example, say there is a class that describes bank accounts. Assuming I can choose to deposit or not deposit money under my name upon creating an account, there is a chance for a meaningful overload. One constructor could take in the name of the account owner and the initial balance as parameters; the overloaded constructor could just take the name as a parameter while setting the initial balance to zero.


Need of constructor in c plus plus?

There is no specific keyword for a constructor in C++. Simply define and declare a method of the class with the same name as the class and it will be a constructor. A constructor with no arguments is the default constructor, a constructor with one argument of class type is the copy constructor, and a constructor with one argument of some other type is the conversion constructor. You can provide other overloaded constructors if you want.


Static can be used in front of a constructor?

No. Static elements belong to the class, and the constructor belongs to the object (which is an instance of a class).


Why you use constructors?

To create an instance of the class that implementing that constructor


How does constructor work?

First line in any constructor has to be either super() or this() not both. If any constructor does not contain either of super() and this(), compiler adds super(). When any constructor is called before excuting the code of the constructor, if it founds this(), it will call another constructor else it will call super() which is the call for the constructor of super class, now again from the super class constructor it will call the super class constructor if available. This is continued until it reaches the top of the class hierarchy. ---- Basically, a constructor is a block of code that gets executed each time a particular instance of a class is created. So, say you've designed a class for working with a database of some sort. When you create an instance of that class, copies of all the variables and functions of that class get attached to the instance-object, and if one of the functions is a constructor function, it will be run as soon as the instance-object is created. This lets you automatically set up conditions for the instance (i.e. establishing connections to different databases or reading data from different tables, or etc.). Depending on the language you're using, classes may or may not automatically call the constructor function of a parent or super class (if such exists, and if you do not provide a constructor for the class in question).


What is meant by copy constructor overloading?

It is meaningless. Copy constructors cannot be overloaded. You either use the compiler-generated default copy constructor or you define your own. Either way, there can only ever be one copy constructor. The purpose of the copy constructor is to construct a new instance of a class (a new object) from an existing instance of the same class (an existing object). By default, the new object's members will be a bitwise copy (a shallow copy) of the existing object's members. If the class acquires a resource through a member pointer, a user-defined copy constructor must be provided in order to perform a deep copy of that pointer, otherwise you end up with two objects sharing the same resource. This problem does not exist when using smart pointers or resource handles rather than raw pointers.


What is difference constructor and function in programming C plus plus?

A Constructor is called when you are making a new instance of a class and member functions are functions that you can call within your class or else call using the instance of that class.for exampleclass Foo {public:int bar;Foo(int bar) {this->bar = bar;}inc_bar(); {this->bar++;}};Foo instance(10); // Constructor is called and bar is set to 10cout


How do you create constructor?

Every class, including abstract classes, MUST have a constructor. Hard Code that into your brain. But just because a class must have one, doesn't mean the programmer has to type it. A constructor looks like this: class Car { Car() { } // The constructor for the Car class } You notice anything missing in the declaration above? There's no return type! Two key points to remember about constructors are that they have no return type and their names must exactly match the class name. Typically, constructors are used to initialize instance variable state, as follows: class Car { int size; String name; Car(String name, int size) { this.name = name; this.size = size; } } In the preceding code example, the Car class does not have a no-arg constructor. That means the following will fail to compile: Car f = new Car(); // Won't compile, no matching constructor but the following will compile: Car f = new Car("Ford", 43); // No problem. Arguments match // the Car constructor. So it's very common for a class to have a no-arg constructor, regardless of how many other overloaded constructors are in the class (constructors can be overloaded just like methods). You can't always make that work for your classes; occasionally you have a class where it makes no sense to create an instance without supplying information to the constructor. A java.awt.Color object, for example, can't be created by calling a no-arg constructor, because that would be like saying to the JVM, "Make me a new Color object, and I really don't care what color it is...." Do you seriously want the JVM making your color choices?


Example of constructor in java?

Every class, including abstract classes, MUST have a constructor. Hard Code that into your brain. But just because a class must have one, doesn't mean the programmer has to type it. A constructor looks like this: class Car { Car() { } // The constructor for the Car class } You notice anything missing in the declaration above? There's no return type! Two key points to remember about constructors are that they have no return type and their names must exactly match the class name. Typically, constructors are used to initialize instance variable state, as follows: class Car { int size; String name; Car(String name, int size) { this.name = name; this.size = size; } } In the preceding code example, the Car class does not have a no-arg constructor. That means the following will fail to compile: Car f = new Car(); // Won't compile, no matching constructor but the following will compile: Car f = new Car("Ford", 43); // No problem. Arguments match // the Car constructor. So it's very common for a class to have a no-arg constructor, regardless of how many other overloaded constructors are in the class (constructors can be overloaded just like methods)


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.