Instance Methods in Java Last Updated : 21 Oct, 2025 Comments Improve Suggest changes 8 Likes Like Report An instance method is a method that belongs to an instance of a class. We must create an object of that class (or have one already) to call an instance method.Instance methods can access and modify instance fields (object state) and can call other instance or static methods.Syntax:modifier return_type method_name( ){ method body ;}modifier: It defines the access type of the method, and it is optional to use.return_type: Method may return a value. Ex:- int, void, String, char, float, etc.method_name: This is the method name you can write anything as you write the variable name.method body: The method body describes what the method does with statements.Example 2: Instance Method Without Parameter Java public class Student{ String name; int age; // Instance method void displayInfo(){ System.out.println("Name: " + name + ", Age: " + age); } public static void main(String[] args){ // Creating an object Student s1 = new Student(); // Assigning values s1.name = "Alice"; s1.age = 20; // Calling instance method s1.displayInfo(); } } OutputName: Alice, Age: 20 Explanation:Student class contains instance variables name and age.The displayInfo() instance method prints their values.We create an object s1, assign values, and call the method to display them.Example 2: Instance Method With Parameter Java import java.io.*; class GFG{ // static method public static void main (String[] args){ // creating object GFG obj = new GFG(); // calling instance method by passing value obj.add(2,3); System.out.println("GFG!"); } // Instance method with parameter void add(int a, int b){ // local variables int x= a; int y= b; int z= x + y; System.out.println("Sum : " + z); } } OutputSum : 5 GFG!Explanation:GFG class has an instance method add() that accepts two integers.The method adds the numbers and prints their sum.We create an object and call add() with parameters 2 and 3.Types of Instance Methods:There are two types of Instance methods in Java:1. Accessor Methods (Getters)Used to read the value of private instance variables.Start with get followed by the variable name (first letter capitalized).Helps in encapsulation by providing controlled access to data.2. Mutator Methods (Setters)Used to modify or update the value of private instance variables.Start with set followed by the variable name (first letter capitalized).Provides a controlled way to change data in a class.Let's get understand by some examples: Java import java.io.*; class account { // private variable-balance private int balance = 50; // accessor method (getter) public int getBalance(){ return balance; } // Mutator method (setter) public void setBalance(int a){ // return balance + a; balance += a; } } class GFG{ public static void main(String[] args){ account obj = new account(); // setting new value for balance obj.setBalance(50); // calling the Mutator (accessor) System.out.println("Your Balance : "+ obj.getBalance()); System.out.println("GFG!"); } } OutputYour Balance : 100 GFG!Explanation:The Account class defines a private variable balance and provides getBalance() and setBalance() methods.The setBalance() method increases the balance by a given amount.In main(), we update the balance and retrieve it using getter and setter methods. Create Quiz Comment S sachinyadavshiv8 Follow 8 Improve S sachinyadavshiv8 Follow 8 Improve Article Tags : Java Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like