1package com.company;
2
3public class Main {
4 static void one(){ // youCanPutWhatEverNameYouLikeInThePlaceOf"One"
5 System.out.println("HELLO");
6 }
7 public static void main(String[] args) {
8 one(); //theTerminalShouldSay"HELLO"
9 }
10}
11
1public class MyClass {
2
3 static void myMethod() {
4 System.out.println("You have called me! My name is: myMethod!");
5 }
6
7 public static void main(String[] args) {
8 myMethod();
9 }
10}
1public class Main
2{
3 static void function(){
4 System.out.println("I am a function!");
5 }
6 public static void main(String[] args) {
7 function();
8 }
9}
1//declare a function like this:
2void function(int parameter1)
3{
4 //function body
5}
6//call the function like this:
7function(1);
1Method is a collection of statements
2which returns a value upon its execution.
3 Method have a return and the method's name may or not be same as the class
4name.
5Method is invoked explicitly.
6Method is not provided by compiler in any case.
7Methods are inherited by child classes.