what is the syntax of function return in Java
Answers
Answer:return is a reserved keyword in Java i.e, we can't use it as an identifier. It is used to exit from a method, with or without a value. return can be used with methods in two ways: Methods returning a value : For methods that define a return type, return statement must be immediately followed by return value.
Explanation:
Explanation:
return is a reserved keyword in Java i.e, we can’t use it as an identifier. It is used to exit from a method, with or without a value.
return can be used with methods in two ways:
Methods returning a value : For methods that define a return type, return statement must be immediately followed by return value.
// Java program to illustrate usage
// of return keyword
class A {
// Since return type of RR method is double
// so this method should return double value
double RR(double a, double b)
{
double sum = 0;
sum = (a + b) / 2.0;
// return statement below:
return sum;
}
public static void main(String[] args)
{
System.out.println(new A().RR(5.5, 6.5));
}
}