CHAPTER 11
Beginner
Methods in Java
Updated: May 17, 2026
5 min read
# CHAPTER 11
Methods in Java
1. Introduction
Methods are reusable blocks of code that perform a specific task. Instead of writing the same calculation code 50 times, you write it once in a method and call it whenever needed. Methods are the foundation of clean, maintainable code.2. Learning Objectives
- Declare and call methods.
- Use parameters and return values.
- Understand method overloading.
- Implement basic recursion.
3. Method Declaration
java
java
4. Parameters and Arguments
- Parameters: Variables defined in the method declaration.
- Arguments: Actual values passed when calling the method.
java
5. Return Types
-
void— returns nothing
-
int,double,String, etc. — returns a value of that type
java
6. Method Overloading
Same method name, different parameter lists.
java
7. Variable Arguments (Varargs)
java
8. Recursion
A method calling itself.
java
9. Common Mistakes
- Missing return statement: Non-void methods must always return a value.
- Infinite recursion: Forgetting the base case causes StackOverflowError.
- Confusing overloading with overriding: Overloading is same class; overriding is inheritance.
10. MCQ Quiz with Answers
Question 1
A method with no return value uses:
Question 2
What is method overloading?
Question 3
What does return do?
Question 4
What is recursion?
Question 5
Without a base case, recursion causes:
Question 6
int... nums is called:
Question 7
Can two methods have the same name in Java?
Question 8
What is static in a method?
Question 9
What is 5! (factorial)?
Question 10
Parameters are defined in the method:
11. Interview Questions
- Q: What is the difference between method overloading and overriding?
-
Q: Can you overload the
main()method? (Yes, but JVM always callspublic static void main(String[]))
- Q: What is the call stack and how does recursion use it?