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. For example, the following declares a method named Show class Stack { . . . boolean isEmpty() { . . . } } Returning a Value from a MethodJava requires that a method declare the data type of the value that it returns. If a method does not return a value, it must be declared to return A Method's NameA method name can be any legal Java identifier. There are three special cases to consider in regards to Java method names: Advanced Method Declaration FeaturesBesides the two required elements of a method declaration, a method declaration may contain other elements as well. These elements declare the arguments accepted by the method, whether the method is a class method, and so on. |