We can directly use these methods just by calling them in the program at any point. It is also known as the standard library method or built-in method. In Java, predefined methods are the method that is already defined in the Java class libraries is known as predefined methods. It is also possible that a method has the same name as another method name in the same class, it is known as method overloading. Multi-word method name: areaOfCircle(), stringComparision() In the multi-word method name, the first letter of each word must be in uppercase except the first word. If the method name has more than two words, the first name must be a verb followed by adjective or noun. While defining a method, remember that the method name must be a verb and start with a lowercase letter. It is enclosed within the pair of curly braces. It contains all the actions to be performed. Method Body: It is a part of the method declaration. If the method has no parameter, left the parentheses blank. It contains the data type and variable name. Parameter List: It is the list of parameters separated by a comma and enclosed in the pair of parentheses. Suppose, if we are creating a method for subtraction of two numbers, the method name must be subtraction(). It must be corresponding to the functionality of the method. Method Name: It is a unique name that is used to define the name of a method. If the method does not return anything, we use void keyword. It may have a primitive data type, object, collection, void, etc. Return Type: Return type is a data type that the method returns. It is visible only from the same package only.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |