a constructor is a method in the class which gets executed when its object is created. Usually, we put the initialization code in the constructor. Writing a constructor in the class is damn simple, have a look at the following sample:
public class Test
{
public Test()
//Initilize code in the constructor. }}
Method:
Constructor is used to create an instance of class. while method is used to perform a specific operation...
select * from
by default constructor's return type is that of a class in which it is defined so no need to write explicitly the return type. [don't know if u know c or not, if yes then it is mallock type casted to the pointer of that class type] a method must[not can...., as even if it returns nothing it should have a return type of VOID] have a return type. just as methods constructors can be public,private,static etc. but as a general guideline it is advisable to have constructors public. constructor anme should be exactly[case sensitive] same as the calss name last but not the least even if u dont define a default constructor then when you instanciate an object ...it is the system who defines one for you and calls it in order to create an instance of object... Regards Sam
Constructor is used to create an instance of object.
Method is used to perform some operations.
->constructor call automatically . constructor is also public or private. constructor is for memory management ->method call forcefully . method only focus on functionality
1. constructor name should match with a class name, but for a method a name could be of anything.
2.constructor don't have any return type, where as a method can have a return type.