Besides the name of the method, the method declaration carries information such as the return type of the method, the number and type of the arguments required by the method, and what other classes and objects can call the method. While this may sound like writing a novel rather than simply declaring a method for a class, most method attributes can be declared implicitly. The only two required elements of a method declaration are the method name and the data type returned by the method. If a method does not return a value, it must be declared to return void . Methods can return either values of primitive data types or of reference data types.
Methods use the return operator to return a value.
Any method that is not declared void must contain a return statement. When returning an object, the returned object's data type must be either a subclass of or the exact class indicated. When returning an interface type, the object returned must implement the specified interface. A Method's Name A method name can be any legal Java identifier. Java supports method name overloading so multiple methods can share the same name.