Methods
A method contains one or more statements. In well-written Java code, each method performs only one task. Each method has a name, and it is this name that is used to call the method. In general, you can give a method whatever name you please. However, remember that main( ) is reserved for the method that begins execution of your program. Also, don’t use Java’s keywords for method names. In the following example we demonstrate how to define methods inside class, although we already have, but a new thing how we can return values from methods as:
class MethodTest { String MethodTest() // String is a return type of the Method MethodTest { return "It's great"; } } public class MethodExample { public static void main(String[] args) { MethodTest obj1 = new MethodTest(); String s = obj1.MethodTest(); System.out.println("Returned Value : " + s); } }