Slide 1
Slide 2
Slide 3

Class Method in java programming (V54)

No Comments

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:


access_modifier: public, private, protected, or default
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

Copied!
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
    }
}

Result:

Watch the video:


Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

back to top