From the course: Oracle Java Foundations
Unlock this course with a free trial
Join today to access over 24,000 courses taught by industry experts.
Define methods - Java Tutorial
From the course: Oracle Java Foundations
Define methods
(gentle music) (transition whooshing) - [Joe] In this module, we'll look at defining methods. We've talked about the components of a class before. We have the class name that you see here at the top, the class declara, in the part of the class declaration. We have variables. Here we have name, which is a string, and size, which is a string and is initialized to the value "S". We also have methods, and methods are where the executable code reside. We have a method called setSize, which if we pass it in a string called newSize, we'll assign that value to the size variable, allowing us to change the size for a customer as needed. We can also find out what the customer size is by calling getSize, and it returns the value of the size variable for us. Okay, so let's see what this looks like. The basic definition of a method is the method name, a return type, methods either return of value or they don't. And if they don't, we have to signify that. And we specify whether or not that method is…