2 comments
Avatar
Hesh Fekry
/* CallingMethodsInSameClass.java
*

  • illustrates how to call static methods a class
  • from a method in the same class
  • /
public class CallingMethodsInSameClass
{
public static void main(String[] args) {
printOne();
printOne();
printTwo();
}

public static void printOne() {
    System.out.println("Hello World");
}

public static void printTwo() {
    printOne();
    printOne();
}
}
Hide Replies 1
Avatar
Administrator
winrid
Properly formatted code will render better:

    /* CallingMethodsInSameClass.java
*
* illustrates how to call static methods a class
* from a method in the same class
*
 */

public class CallingMethodsInSameClass {
  public static void main(String[] args) {
      printOne();
      printOne();
      printTwo();
  }

  public static void printOne() {
      System.out.println("Hello World");
  }

  public static void printTwo() {
      printOne();
      printOne();
  }
}
We will however, improve the system so it formats the code snippet for you.
Enter your email to vote. We won't send you any marketing or solicitation emails.