Method Types in Java
A Complete Overview
Your Name | Date
Introduction
• Methods are blocks of code that perform specific tasks.
• They help in code reusability and modular programming.
• Methods in Java can be classified based on return type, parameters, access, invocation, and special beh
Based on Return Type
Void Methods:
• Do not return a value
Example:
public void greet() { [Link]("Hello!"); }
Return-Type Methods:
• Return a value of specified type
Example:
public int sum(int a, int b) { return a + b; }
Based on Parameters
No-Argument Methods:
• No input parameters
Example: void displayMessage() {}
Parameterized Methods:
• Accept input parameters
Example: void greetUser(String name) {}
Based on Access Modifiers
• Public – accessible anywhere
• Private – accessible only within class
• Protected – accessible in package & subclasses
• Default – accessible only within package
Based on Invocation
Instance Methods:
• Belong to objects
• Called using object reference
Static Methods:
• Belong to class
• Called using class name
• Declared with 'static'
Special Method Types
• Abstract Methods – no body, must override
• Final Methods – cannot be overridden
• Synchronized Methods – thread-safe
• Native Methods – implemented outside Java
Summary Table
• Void Method – No return – void greet() {}
• Return-Type Method – Returns value – int sum() {}
• No-Arg Method – No parameters – void display() {}
• Parameterized Method – With parameters – void greet(String name) {}
• Instance Method – Needs object – [Link]()
• Static Method – Belongs to class – [Link]()
• Abstract Method – No body, must override – abstract void draw();
• Final Method – Cannot override – final void show(){}
• Synchronized Method – Thread-safe – synchronized void update(){}
• Native Method – Implemented outside Java – native void nativeMethod();
Conclusion
• Java methods organize code into reusable blocks.
• Understanding method types helps in OOP design & optimization.
• Use access modifiers, static/instance, and special methods as needed.