Java has three different types of methods. Programmer can develop any type of method depending on the scenario.

1. Static methods: A static method is a method that can be called and executed without creating an object. In general, static methods are used to create instance methods.

Static method can be invoked directly via class name i.e.; we don't have to create an object for a class in order to initiate static method.

You can get more information on static methods here.

2. Instance methods: These methods act upon the instance variables of a class. Instance methods are being invoked with below syntax


Instance methods are classified into two types

a. Accessor methods: These are the methods which read the instance variables i.e.; just go access the instance variables data. Generally these methods are named by prefixing with "get".

b. Mutator method: These are the methods, which not only read the instance variables but also modify the data. Generally these methods are named by prefixing with "set".
* A demo class to explain instance methods
* @author Santhosh Reddy Mandadi
* @since 02-Mar-2012
* @version 1.0
class Person
//instance variables
String name;
int age;
char sex;
//To initialize variables with parameterized constructor
public Person(String name, int age, char sex)
{ = name;
this.age = age; = sex;
public void display()
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Sex: "+sex);
Person modify(Person p)
{ = "Santhosh";
p.age = 27; = 'M';
return p;

class InstanceMethodsDemo
public static void main(String args[]) throws Exception
Person p = new Person("Revathi", 23, 'F');
Person p1 = p.modify(p);
Person p2 = p1.modify(new Person("Upendar", 25, 'M'));

3. Factory methods: A factory method is a method that returns an object to the class to which it belongs. All factory methods are static methods.

Eg: NumberFormat obj = NumberFormat.getNumberInstance();