Java Programming Lesson 7 Part-2 | Functions / Methods in Java for Beginners
LESSON-7 PART-2
Functions / Methods in Java
✅ Here is Lesson-7: Functions / Methods in Java — Simple to Advanced 🚀
📘 Lesson-7: Functions / Methods
A method is a block of code that performs a specific task and can be reused.
✅ Why Methods?
✔ Avoid repeating code
✔ Make programs cleaner
✔ Easier to debug
✔ Improve organization
✅ Syntax of a Method
Example:
✅ Types of Methods
1️⃣ Method with No return, No parameters
Call:
2️⃣ Method with parameters
Call:
3️⃣ Method with return value
Call:
4️⃣ Method Overloading
Same method name but different parameters ✅
✅ Full Example Program
✅ Method Calling Rules
| Feature | Keyword |
|---|---|
| Used inside main without creating object | static |
| Needs object to call | Non-static |
Example (non-static):
🧠 KEY TAKEAWAYS
✔ Methods = Reusable code
✔ Parameters send data → return values bring data back
✔ Static methods → direct call
✔ Non-static methods → require object
✔ Method Overloading allowed ✅
📝 Practice Exercise
Write a program with:
-
Method
add()→ returns sum -
Method
sub()→ returns subtraction -
Method
display()→ prints your full name
📌 Then call them from main() ✅


Nice Post, Keep it up
ReplyDelete