Prgm:This program will show method with parameter and with return type.here method takes two parameter and this method has a return type that's double.check the program here.
class MulOfNumber
{
//return type is double and method taking two double type parameter
double mul(double x,double y)
{
double result=x*y;
return result; //return result
}
}
class MethodExample
{
public static void main(String args[])
{
MulOfNumber sn=new MulOfNumber();
double z=sn.mul(5.2,2.5);
System.out.print("Result is : "+z);
}
}
O/P:Result is : 13.0
Example of Method without any parameter and without return type:
class Calculate
{
int num1,num2;
Calculate(int x,int y)
{
num1=x;
num2=y;
}
void sum()
{
int res=num1+num2;
System.out.println("Result is : "+res);
}
}
class methodWithoutParameter
{
public static void main(String args[])
{
Calculate c=new Calculate(21,44);
c.sum();
}
}
O/P:
Result is : 65
No comments:
Post a Comment