Java: Methods & Classes
What you will learn
Class structure, method signatures, and the static keyword.
A class is a blueprint. A method is a named block of code inside a class.
public class Greeter {
public static String greet(String name) {
return "Hello, " + name + "!";
}
public static void main(String[] args) {
System.out.println(greet("Alice"));
}
}
Method anatomy
- access modifier:
public,private,protected - static: belongs to the class, not instances
- return type:
voidmeans returns nothing - parameters: in parentheses
- body: in
{ }
Quick check below!