Note :- Before we learn about Method we should learn that what is Method.
Method Argument
Method can accepts any no. of Parameters(argument), also it can accept any datatype as parameter. Method can also accept object as parameter. The method parameter must have datatype and should be pass in a sequence as they must be accepted by method in the same sequence.
पद्धति(Method) किसी भी संख्या में पैरामीटर (तर्क) को स्वीकार कर सकती है, यह भी पैरामीटर(Parameter) के रूप में किसी भी डेटाटाइप(datatype) को स्वीकार कर सकती है। विधि ऑब्जेक्ट (object)को पैरामीटर(Parameter) के रूप में भी स्वीकार कर सकती है। विधि(Method) पैरामीटर(Parameter) में डेटाटाइप(datatype) होना चाहिए और एक अनुक्रम(Sequence) में पास होना चाहिए क्योंकि उन्हें उसी क्रम में विधि(Method) द्वारा स्वीकार किया जाना चाहिए।
Method Overloading is a feature that allows a class to have more than one method having same name. if their argument lists are different.
मेथड ओवरलोडिंग(Method Overloading) एक ऐसी सुविधा है जो एक वर्ग(class) को एक से अधिक विधियो(Method) को एक ही नाम(Same name)रखने की अनुमति देती है। अगर उनके तर्क(Arguments) अलग हैं।
ex :-
class test
{
public int add_no(int a, int b)
{
int c;
c = a+b;
return c;
}
public static void main(String args[])
{
पद्धति(Method) किसी भी संख्या में पैरामीटर (तर्क) को स्वीकार कर सकती है, यह भी पैरामीटर(Parameter) के रूप में किसी भी डेटाटाइप(datatype) को स्वीकार कर सकती है। विधि ऑब्जेक्ट (object)को पैरामीटर(Parameter) के रूप में भी स्वीकार कर सकती है। विधि(Method) पैरामीटर(Parameter) में डेटाटाइप(datatype) होना चाहिए और एक अनुक्रम(Sequence) में पास होना चाहिए क्योंकि उन्हें उसी क्रम में विधि(Method) द्वारा स्वीकार किया जाना चाहिए।
Method Overloading is a feature that allows a class to have more than one method having same name. if their argument lists are different.
मेथड ओवरलोडिंग(Method Overloading) एक ऐसी सुविधा है जो एक वर्ग(class) को एक से अधिक विधियो(Method) को एक ही नाम(Same name)रखने की अनुमति देती है। अगर उनके तर्क(Arguments) अलग हैं।
ex :-
class test
{
public int add_no(int a, int b)
{
int c;
c = a+b;
return c;
}
public static void main(String args[])
{
test t1 = new test();
int d;
d = t1.add_no(10, 20);
System.out.println(d);
}
}
Method (function) Overloading :-
It means using the same thing for different purpose, function overloading means we can use the same function name to create function that perform a variety of different task, this is a concept of compile time polymorphism.
इसका मतलब अलग-अलग उद्देश्य के लिए एक ही चीज़ का उपयोग करना है, फ़ंक्शन ओवरलोडिंग(function overloading) का अर्थ है कि हम एक ही फ़ंक्शन(function) नाम का उपयोग फ़ंक्शन बनाने के लिए कर सकते हैं जो विभिन्न प्रकार के कार्य करते हैं, यह संकलन समय बहुरूपता(compile time polymorphism) की अवधारणा है।
ex :-
class test
{
public void show()
{
System.out.println("Method without parameter :");
}
public void show(int a)
{
System.out.println("Method with parameter :");
}
public void show(string name, int a)
{
System.out.println("method with two parameter :");
}
public static void main(string args[])
{
test t1 = new test();
t1.a = 10;
t1.name = "Vishmyblog";
System.out.println(name);
System.out.println(a);
t1.show();
}
}
Method Overriding :-
Declaring a method in subclass which is already present in parent class is called as method overriding. In a class hierarchy, when a method in a subclass has the same name and type signature as a method in a super(parent) class, then the method in a subclass is said to override the method in the super class. Method Overriding is a concept of run time polymorphism.
उपवर्ग(Subclass) में एक विधि(Method) की घोषणा करना जो पहले से ही मूल वर्ग(super class) में मौजूद है जिसे विधि अधिभावी(Method Overriding) कहा जाता है। एक वर्ग पदानुक्रम(class hierarchy) में, जब किसी उपवर्ग(Subclass) में एक विधि(Method) का नाम और प्रकार हस्ताक्षर(Type signature) होता है, तो एक सुपर (अभिभावक) वर्ग(Parent class) में एक विधि(Method) के रूप में, तब उपवर्ग(Subclass) में विधि को सुपर क्लास(Super class) में विधि को ओवरराइड करने के लिए कहा जाता है। मेथड ओवरराइडिंग(Method Overriding) रन टाइम पोलिमोर्फ़िज्म(run time polymorphism) की अवधारणा(Concept) है।
ex :-
class Base
{
public void show(int a)
{
System.out.println("this is parent class :");
}
class Child extends Base
{
System.out.println("this is child class :");
}
public static void main(String args[])
{
Base b1 = new Base();
b1.show();
}
}
int d;
d = t1.add_no(10, 20);
System.out.println(d);
}
}
Method (function) Overloading :-
It means using the same thing for different purpose, function overloading means we can use the same function name to create function that perform a variety of different task, this is a concept of compile time polymorphism.
इसका मतलब अलग-अलग उद्देश्य के लिए एक ही चीज़ का उपयोग करना है, फ़ंक्शन ओवरलोडिंग(function overloading) का अर्थ है कि हम एक ही फ़ंक्शन(function) नाम का उपयोग फ़ंक्शन बनाने के लिए कर सकते हैं जो विभिन्न प्रकार के कार्य करते हैं, यह संकलन समय बहुरूपता(compile time polymorphism) की अवधारणा है।
| Overloading in JAVA |
ex :-
class test
{
public void show()
{
System.out.println("Method without parameter :");
}
public void show(int a)
{
System.out.println("Method with parameter :");
}
public void show(string name, int a)
{
System.out.println("method with two parameter :");
}
public static void main(string args[])
{
test t1 = new test();
t1.a = 10;
t1.name = "Vishmyblog";
System.out.println(name);
System.out.println(a);
t1.show();
}
}
Method Overriding :-
Declaring a method in subclass which is already present in parent class is called as method overriding. In a class hierarchy, when a method in a subclass has the same name and type signature as a method in a super(parent) class, then the method in a subclass is said to override the method in the super class. Method Overriding is a concept of run time polymorphism.
उपवर्ग(Subclass) में एक विधि(Method) की घोषणा करना जो पहले से ही मूल वर्ग(super class) में मौजूद है जिसे विधि अधिभावी(Method Overriding) कहा जाता है। एक वर्ग पदानुक्रम(class hierarchy) में, जब किसी उपवर्ग(Subclass) में एक विधि(Method) का नाम और प्रकार हस्ताक्षर(Type signature) होता है, तो एक सुपर (अभिभावक) वर्ग(Parent class) में एक विधि(Method) के रूप में, तब उपवर्ग(Subclass) में विधि को सुपर क्लास(Super class) में विधि को ओवरराइड करने के लिए कहा जाता है। मेथड ओवरराइडिंग(Method Overriding) रन टाइम पोलिमोर्फ़िज्म(run time polymorphism) की अवधारणा(Concept) है।
| Overriding in JAVA |
ex :-
class Base
{
public void show(int a)
{
System.out.println("this is parent class :");
}
class Child extends Base
{
System.out.println("this is child class :");
}
public static void main(String args[])
{
Base b1 = new Base();
b1.show();
}
}
0 Comments