Search⌘ K
AI Features

Methods

Explore how Java methods function as abstractions for object actions, learn to interpret method signatures, understand access control with public and private keywords, use static methods, and recognize return types. This lesson helps you grasp how methods enable coding functionality without exposing details.

Methods determine what functions an object can perform. In fact, another name for method is literally function.

Method: an abstraction

A class’s method is an abstraction for the user. The user only needs to know what a method does, not how a method does something.

For example, in a previous lesson, we discussed the Quadrilateral class. It may have a method to calculate the area. Let’s call it calculateArea. As a programmer, you do not need to know how calculateArea internally works. You just know that, given some parameters, this function will calculate the area for you. This is the power of abstraction! Methods are nothing but the means of creating such an abstraction.

Let’s take a look at the anatomy of a typical Java method.

Signature

The signature of a Java method conceals quite a lot of information. Given below is the signature of the ...