How do I write method names in Java?


While writing a method name we should follow the camel case i.e. first letter of the first word should be small and the first letters of the remaining (later) words should be capital.

Example

public class Test {
   public void sampleMethod() {
      System.out.println("This is sample method");   
   }
   public void demoMethod() {
      System.out.println("This is demo method");   
   }
   public static void main(String args[]) {
      Test obj = new Test();
      obj.sample();
      obj.demo();
   }
}

Output

This is sample method
This is demo method

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements