To call a method in Java, do this:
object.myMethod()
.Here's how you do it:
public class Example {
public void printHello() {
System.out.println("Hello!");
}
public void print(String text) {
System.out.println(text);
}
}
Example example = new Example();
// 1) Call a method without parameters
// This will print: Hello!
example.printHello();
// 2) Call a method with a parameter
// This will print: Hello World!
example.print("Hello World!");
// 3) Call a static method
double twoSquared = Math.pow(2, 2);
System.out.println(twoSquared); // 4.0