OO Programming with Java


Hello World !

Classes generally propose many operations that can be defined as follow:

  1. Change the code with:
public class Hello {
  public static void sayHello(String s) { // DEFINITION of an operation
    System.out.println("Hello "+ s +" !");
  }
  public static void main(String args[]) {
    Hello.sayHello("John"); // CALL of an operation
    Hello.sayHello("Kate");
    Hello.sayHello("Bill");
  }
}

Then (recompile and) run with:

java -cp . Hello.java
> Hello John !
> Hello Kate !
> Hello Bill !

go further


6 - 17