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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Understanding encapsulation7m 19s
-
Creating and instantiating custom classes4m 51s
-
(Locked)
Creating nested and anonymous classes4m 17s
-
(Locked)
Visualizing class relationships3m 43s
-
(Locked)
Storing data in instance variables6m 2s
-
(Locked)
Declaring instance and static methods3m 59s
-
(Locked)
Using constructor methods4m 56s
-
(Locked)
Using static variables as constants3m 3s
-
(Locked)
Declaring and using enum types5m 17s
-
(Locked)
-
-
-
-