Posts

Showing posts with the label same name methods java

Nesting Method and Method Overloading in Java जावा में नेस्टिंग ऑफ मेथड्स और मेथड ओवरलोडिंग

Nesting of Methods:- When one method of a class calls another method of the same class using just its name, this is called nesting of methods. This allows internal functionality reuse within the same class. जब एक मेथड, उसी क्लास की किसी अन्य मेथड को केवल उसके नाम का उपयोग करके कॉल करता है, तो इसे "नेस्टिंग ऑफ मेथड्स" कहा जाता है। इससे एक ही क्लास के भीतर मेथड की पुनः उपयोगिता (reuse) संभव होती है। Example: class NestedMethods { private int a, b; NestedMethods(int m, int n) { a = m; b = n; } int largest() { if (a > b) return a; else return b; } void display() { int l = largest(); // Method nesting System.out.println("The Greatest Number is : " + l); } } public class nested_method_example { public static void main(String args[]) { NestedMethods obj = new NestedMethods(15, 36); obj.display(); } } Method Overloading:- Method overloading allows multiple methods t...