Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

exmple of methods in java

class Main {

  // method with no parameter
  public void display1() {
    System.out.println("Method without parameter");
  }

  // method with single parameter
  public void display2(int a) {
    System.out.println("Method with a single parameter: " + a);
  }

  public static void main(String[] args) {
    
    // create an object of Main
    Main obj = new Main();

    // calling method with no parameter
    obj.display1();
    
    // calling method with the single parameter
    obj.display2(24);
  }
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #exmple #methods #java
ADD COMMENT
Topic
Name
1+6 =