Methods
Get to know about the role of methods in classes.
The purpose of methods
Methods act as an interface between a program and the data fields of a class in the program.
These methods can either alter the content of the data fields or use their values to perform a certain computation. All the useful methods should be public, although, some methods which do not need to be accessed from the outside could be kept private.
Definition and declaration
A method is a group of statements that performs some operations and may or may not return a result.
Here is an example of a method in Java:
Get hands-on with 1400+ tech skills courses.