What is the difference between constructor and method?
praveen
Select an image from your device to upload
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 object.
Method is used to perform some operations.
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.