Java Static Methods: Void, Return Value, Parameters & Interview Prep

Day 27/100 – Java Programming Journey. Today I learned about static methods in Java and how they behave based on return types and parameters. This topic cleared many small but important doubts. 🔹 Types of static methods I learned 1️⃣ Static method without return value (void) Used when a method performs an action but doesn’t send anything back. 2️⃣ Static method with return value (int, double, etc.) Used when a method processes data and returns a result to the caller. 3️⃣ Static method with parameters Example: static int add(int a, int b) Here I learned an important rule: Each parameter must have its own data type Writing int a, b is valid only inside a method body, not in the parameter list 4️⃣ Static method without parameters Used when no external input is required and the logic is fixed. 🔹 Parameter vs Argument (very important) Parameter → acts like a container that receives values Argument → the actual value passed to the method during the call ⚠️ Interview Question I learned today What happens if we write statements after a return statement? 👉 They cause a compile-time error because return ends the method execution. Any code written after it becomes unreachable. 💡 Understanding static methods helps in writing utility functions, reusable logic, and clean program flow. Learning step by step and clearing fundamentals. #Java #StaticMethods #ProgrammingBasics #100DaysOfCode #LearningJourney #InterviewPrep 10000 Coders Meghana M

To view or add a comment, sign in

Explore content categories