From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declaring instance and static methods

Declaring instance and static methods - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Declaring instance and static methods

- As I've previously described, when you create a method that's a member of a class, and you don't include the static key word, that means it's an instance method. A class that's designed to encapsulate data, such as my model class, named Olive, typically will have instance methods known as setters and getters. The getter is called the accesor method, and the setter is know as the modifier method. If your class already has instance variables, your IDE typically will be able to generate the setters and getters for you. And IntelliJ IDEA does this well. I'll make a bit of space below the variable declarations, then I'll right click and choose Generate. And from the menu that appears I'll chose getter and setter. Then I'll chose all three instance variables, and click okay. And that generates public methods. They all start with the words get or set, and finish with the variable names. Getters simply return the value, and setters receive an argument. Notice within a setter method, the key…

Contents