Skip to content

kannah-coder/Methods-JAVA

Repository files navigation

Methods-JAVA

A method in Java is a block of code inside a class that performs a specific task, and can be called (invoked) when needed. It helps achieve: Code reusability Modularity Readability Encapsulation (keeping logic inside the class)

⚙️ Method Overloading in Java (Advanced Example)

This project demonstrates Method Overloading in Java with multiple complex cases — covering data type variations, varargs, and type promotions.


🧩 Code Explanation

🔹 MathOperations Class

This class defines multiple overloaded add() methods, each handling different types or numbers of arguments.

✅ Types of Overloading Demonstrated

Method Signature Description
int add(int, int) Adds two integers
double add(double, double) Adds two doubles
int add(int, int, int) Adds three integers
int add(int... numbers) Adds any number of integers using varargs
String add(String, String) Concatenates two strings
double add(long, float) Demonstrates type promotion

📁 METHODS ┣ 📜 Methods.java ┣ 📜 MethodOverloading.java ┣ 📜 README.md ┗ 📜 .gitignore ┣ BasicsMethods.java ┣ MethodsShowcase.java

This file helps you about the what is function which to common to all languages

MethodsShowcase.java is a Java program demonstrating a variety of methods in a single file. It covers:

Instance methods Method overloading Recursion Methods with arrays Varargs (variable number of arguments) Private methods Methods calling other methods

This program is designed as a learning reference for Java beginners to understand different ways to write and use methods.

Using static avoids creating objects For small programs or utility methods, making them static is easier. You can call them directly inside main():

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages