After the simple ‘HelloWorld’ program this is going to be easy too.
A method is a collection of coding which is specified by its name and signature.It is called to perform a specific task.
public class Cars
public static void sampleMethod() //this is a method which prints some message
System.out.println(“This is a method”);
public static void main(String args)
sampleMethod(); // calling the method sampleMethod
- Here the method modifier is static because everything inside the static field will be static.So to call the method inside the main method ‘public static void main(String args)’ we defined it as static.