0% found this document useful (0 votes)
6 views9 pages

Method Types in Java

The document provides an overview of method types in Java, categorizing them based on return type, parameters, access modifiers, invocation, and special characteristics. It explains void methods, return-type methods, no-argument methods, parameterized methods, instance and static methods, as well as abstract, final, synchronized, and native methods. Understanding these classifications is essential for effective object-oriented programming and code optimization.

Uploaded by

shraddha jain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Method Types in Java

The document provides an overview of method types in Java, categorizing them based on return type, parameters, access modifiers, invocation, and special characteristics. It explains void methods, return-type methods, no-argument methods, parameterized methods, instance and static methods, as well as abstract, final, synchronized, and native methods. Understanding these classifications is essential for effective object-oriented programming and code optimization.

Uploaded by

shraddha jain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like