Method, constructor, this keyword in Java

Method: Method is a member of class used to keep codes. It is a process which defines how data of the class could be used.


type name(parameter_list) {

body of method;


Constructor: Constructor is used to intialize an object. The name of constructor is same as the name of class where it is created.

class_variable = new classname( );

where, classname() is the constructor to a class. If no constructor is declared then in Java, a default constructor is created automatically.

this keyword: this keyword is used to create a reference to the object in a method.

For Example:

test(int a, intb) {

this.a = a;

this.b = b;


Leave a Reply