Page 116 - 2617_JSSPS_C-7
P. 116
Method Name
Parameter List
Body of the Method
Let us study these in details.
Header of Method
When a method is declared, the first line is known as the method header or method prototype. This
line contains the access specifier, return type, method name and a list of parameters. Let us consider
the following example:
public int sum (int i, int j)
Parameter List
Method Name
Return Type
Access Specifier
Method Signature
Method signature is a part of method header containing only the name of the method along with
parameter list. For example,
sum (int i, int j)
Access Specifier
Since methods can be accessed by other classes, the same class or other methods, we need to apply
some restrictions on the accessibility of the methods. This is done by the access specifiers. An access
specifier or access modifier specifies the boundary for a method in which it is accessible. There are
three types of access specifiers in Java which are as follows:
The public Access Specifier: The public access specifier allows us to give permissions to a method
accessible anywhere inside the class and outside the class. For example,
public int sum (int i, int j)
The private Access Specifier: The private access specifier restricts a method accessibility outside
the class. Only the methods of the same class can access a private method. For example,
private int sum (int i, int j)
The protected Access Specifier: The protected is a special type of access specifier which allows
methods of the same class and inherited class can access a protected method. For example,
protected int sum (int i, int j)
Premium Edition-VII
114

