Class Methods
A class method is a block of code inside a class that performs a specific action. Methods define the behavior of objects that are created from the class.
Syntax:
• static: optional — used if the method belongs to the class
• return_type: the data type returned (int, void, String)
• methodName: the name of the method
• parameters: inputs (optional)
Source Code: Student.java
public class Student {
// Method to print a message
public void greet() {
System.out.println("Hello! Welcome to Java Class.");
}
public static void main(String[] args) {
Student s1 = new Student(); // Create object
s1.greet(); // Call the method
}
}Watch the video:
Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

