Methods Class 9 10
Methods Class 9 10
User-defined methods
Methods are the block of code which performs specific tasks. Methods are
also called functions, routines, etc.hu7
Based on ‘static’ we have two types: static and non-static. The method
with ‘static’ keyword is a static method and without ‘static’ keyword is a
non- static method.
Classification of functions:
User-defined methods
The methods that are defined by the programmers are called user-defined
methods.
Method header is the first line that we write. Public keyword in main-
method statement is an axis specifier. Generally, we start the statement
with an axis specifier. Static keyword is an axis modifier. The ‘void’ is
return type or void.
Method prototype
The part of the method header which includes the return type or void,
method name and parameters list.
Syntax:
Method Signature
the part of method header from the method name to the parameters
list
the part of method definition which includes the method name and the
parameters list.
Syntax:
Advantages of methods
Types of Methods
The method which has keyword static is a static method. It can be invoked
directly by its name within the class and if the method is in a different
class, then the method will be invoked with its class name.
Example:
className.methodName();
the method which does not have the static keyword in a non- static
method. These methods need to be invoked by object of a class, created
example:
objectname.methodName();
types of variables: