answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2011-02-27 14:14:32

The differences are:

  • Methods have return types but constructors dont
  • Methods can have any name but constructors name must match exactly with the class name
001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0

Your Answer

Related Questions


really there is no difference between constructor overloading and metho overloading


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();


JavaThere is really no such thing as a static constructor in Java. The closest thing that comes to mind is a factory class, which calls a private constructor when a static method is called.class A {// This private constructor can't be called by any other class.private A() {}// Here is your "static" constructorpublic static A getInstance() {return new A();}}


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


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.


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.


Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but 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.


A class is a set of methods grouped together. An object is an instance of a class whose constructor method sets aside a block of memory to store data.


There is no comparison between methods and constructors. They are both present for a reason and each has its own purpose.


No. Java does not support copy constructor


Fuction and method are same . In java we call function as a method...thres no diff between them...


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.


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.


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


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.


Explicit means done by the programmer. Implicit means done by the JVM or the tool , not the Programmer. For Example: Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor. Explicit is opposite to this , ie. programmer has to write .


Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but 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.


The This keyword references the current object. It can be used in an instance method or constructor for an object.


A constructor is technically a type of method, but it is a very special type. Whereas other methods can be used to do just about anything, the only purpose of a constructor method is to create an instance of the class that contains it, often with parameters passed to it through another part of the program. This instance is called an "object" and is a central part of not only Java, but other object-oriented languages as well. A constructor method always has the same name as its containing class, and does not have a return type. Think of it this way: a class in Java is like a generic blueprint for a house. Your instance variables are like different attributes of the house - how many bathrooms will your house have, what colour will it be? Once you decide on the exact specifications for your house, you can give those parameters to the construction company, which will actually create that house. That's what a constructor method does - takes input parameters (or, lacking them, sets defaults) and creates an object.


Every class has at least one it's ownconstructort. Constructor creates a instance for the class. Constructor initiates (initialize) something related to the class's methods. Constructor is the method which name is same to the class. But there are many difference between the method (function) and the Constructor. In this example we will see that how to to implement the constructor feature in a class. This program is using two classes. First class is another and second is the main class which name is Construct. In theConstruct class two objects (a and b) are created by using the overloaded another Constructor by passing different arguments and calculated the are of the different rectangle by passing different values for the another constructor.


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.


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



Copyright ยฉ 2020 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.