answersLogoWhite

0


Best Answer

A constructor is a special method that gets executed when the object is created.

User Avatar

Wiki User

โˆ™ 2017-06-08 14:27:52
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar
Study guides

Mixture

1 card

Class

โžก๏ธ
See all cards
5.0
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
1 Review
More answers
User Avatar

Wiki User

โˆ™ 2018-03-18 11:53:46

Constructors have no return value.

User Avatar

Add your answer:

Earn +20 pts
Q: How does constructor differ from method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is constructor and main method?

The main method is the method called when the Java application is started The constructor is called whenever a new object is instantiated.


Is constructor overloading same as method overloading.yes or no. explain?

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


Are you required to write a constructor method for a class?

No. If you do not write a constructor for you classes, the default Object constructor can still be used.


What is first call in struts2 default constructor or validate method?

Default Constructor will be called first . If you override Validate method , then validate method will be called .


Can a constructor be defined within a method in java?

No.


Differene betwee constructor overloading same as method overloading?

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 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.


What is the diffferent between method and constructor?

Both are functions, i.e., places where you can write code. A constructor is simply a special method that is invoked automatically when an object is created.


Should the constructor name and class name be same?

Yes, a constructor name should always be the same as the class name. You do not directly call the constructor when you instantiate an object, so how the machine knows which method call? Easy, our constructor is always a method with the same name as the class and with no return value.


What are the Differences between constructor overloading and method overloading in java?

really there is no difference between constructor overloading and metho overloading


Which key word is used as 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 the difference between constructor and method in java?

A constructor is a special method that has the same name as the class name, and it cannot be invoked or called like a method call, it must be invoked by the new operator. For example, new Object();


What is a constructor method in java?

A constructor is usually the first method that gets invoked when a class is instantiated. This method usually creates the class object and sets initial variable values in order for the class object to do its functions. A Constructor in java cannot have a return type. It always creates and returns an object of the class for which it is the constructor. You cannot return a value from a constructor explicitly and if you try to do that, the compiler will give an error. The system knows that the purpose of the constructor is to create an object of the class and it will do the same irrespective of whether you declare a return type or not.


Difference between method overloading and constructor overloading?

There is no difference between them.


A subclass can call constructor method defined by its super class?

True


What is a constructor in programming?

A constructor, in object oriented programming concept is a method which has the same name of the class where it is defined. It will be called when an object is created for that class. The job of the constructor is the initialization of the members of the class.


Why constructor rather than classes in java?

Constructor is not an alternative to class. In Java, you create classes; the classes contain methods - including the constructor, which can be viewed as a special method. If you want to have a constructor, you need a class that surrounds it, so it's not one or the other.


What is the difference between Constructor and Function or Method?

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. Constructor needs to have the same name as that of the class whereas functions need not be the same. * There is no return type given in a constructor signature (header). The value is this object itself so there is no need to indicate a return value. * There is no return statement in the body of the constructor. * The first line of a constructor must either be a call on another constructor in the same class (using this), or a call on the superclass constructor (using super). If the first line is neither of these, the compiler automatically inserts a call to the parameterless super class constructor.


Difference between constructor and method?

Assuming you mean Java: A constructor is very similar to a "normal" method, in that it is a place to type commands. The main differences is that a constructor is invoked automatically every time an object of the specified class is instantiated. With respect to syntax, there are two differences: (1) The constructor must have the same name as the class (including upper- and lowercase), and (2) The constructor has no declared return value, not even void.


Does java class must have public method?

no you can have a class with no public methods and even with a a private constructor public class Example { //constructor private Example(){ } }


What is a constructor and its mandatory to use constructor in a class?

A constructor is a method that is invoked when an object is created. As to being mandatory, that really depends on the programming language; in the case of Java, each class must have a constructor, however, in many cases Java will automatically provide a default constructor, so you don't really need to program it.


Why constructors can't be virtual?

We can't override a constructor. When any method is declared as virtual it should be overridden in its derived class. Since constructor is used for initialising the variables and if declare a constructor as virtual it cant be overridden


What is super class construter?

A superclass constructor is the constructor of the superclass. Constructor is a special method that runs automatically as soon as a method is instantiated (created). Superclass is the class on which a certain class is based. This is what is known as "inheritance" - classes can be based on other classes. This is done as a way of organizing classes, and for code reuse - that is, reducing the amount of duplicate code.


Difference between overloading and overwriting a constructor?

Overloading constructor means when you have multiple constructors in a class but with different number of arguments. We cannot override a constructor, but we can override a method having same arguments and same return type. This means when I subclass a particular class then I can call the superclass's class method and override that with subclass's own logic.


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.