Different Ways of Calling Methods in JAVA

Different Ways of Calling Methods in JAVA

There are three different ways of calling a method in JAVA :-

  1. Use of static method
  2. Without static method and inside same class
  3. Without static method and inside another class

1. Use of static method

When we use a static method we can call the method without creating an object of the class.

Output

 

 

2. Without static method and inside same class

When we use a method without static keyword we need to create an object of the class.

Output

3. Without static method and inside another class

When we use a static method we can call the method without creating an object of the class. When the method is in a different class then we need to create an object of the class where the method resides.

Output

Share Me!
  •  
  •  
  •  
  •  
  •  
  •