You are on page 1of 1

● User-defined Method: The method written by the user or programmer

is known as a user-defined method. These methods are modified


according to the requirement2.
// User-defined method
public class Main {
// User-defined method
void myMethod() {
System.out.println("Hello World!");
}

public static void main(String[] args) {


Main myObj = new Main(); // Create an object of class Main
myObj.myMethod(); // Call the method
}
}

● Predefined Method: Predefined methods are the methods that are


already defined in the Java class libraries. We can directly use these
methods just by calling them in the program at any point2.
// Predefined method
public class Main {
public static void main(String[] args) {
String txt = "Hello World";
System.out.println(txt.toUpperCase()); // Predefined method
}
}

You might also like