Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet52/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   48   49   50   51   52   53   54   55   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Function Overloading
At  the  point  when  a  class  has  two  or  more  methods  by  same  name  however  diverse
parameters,  it  is  known  as  method  overloading.  It  is  not  the  same  as  overriding.  In
overriding a method has same name, number of parameters, data type and so on.
The underneath illustration clarifies the same:
public class Myoverloading{
public static void main(string[] args) {
int x = 50;
int y = 34;
double s = 14.3;
double r = 13.6;
int resultant1 = minfunc (x, y);
double resultant2 = minfunc (s, r);
System.out.println(“Value of minfunc = ” + resultant1);
System.out.println(“Value of minfunc = ” + resultant2);
}
public static int minfunc(int num1, int num2) {
int minval;
if (num1 > num2)
minval = num2;


else
minval = num1;
return minval;
}
public static double minfunc(double num1, double num2) {
double minval;
if (num1 > num2)
minval = num2;
else
minval = num1;
return minval;
}
Over-loading systems makes program clear. Here, two systems are given same name yet
with distinctive parameters.

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   48   49   50   51   52   53   54   55   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling