May 24, 2025

Anonymous inner class can have multiple methods ?

Yes. Its possible. You can have multiple methods in anonymous inner class. Check the below example.

interface myInterface {
    void welcome(String string);
    void test();
}

public class innerClassTest {

	public static void main(String[] args) {

		myInterface obj = new myInterface() {
        	public void welcome(String string) {
        		System.out.println("welcome method");
        	}
        	public void test() {
        		System.out.println("test method");
        	}
        };
        obj.welcome("hi");
        obj.test();
	}

}

One thought on “Anonymous inner class can have multiple methods ?

Leave a Reply

Your email address will not be published. Required fields are marked *