Is it Mandatory to declare Methods with a Return Type in Method Declaration in Java?
Is it Mandatory to declare Methods with a Return Type in Method Declaration in Java?
In Java it is mandatory to declare Methods with a return type in a method declaration!
The data type of the return value in a method must correspond to the method declared return type if not ‘void‘. The return types for methods must be of primitive type, that is, it has to be pre-defined and named as a reserved key word in Java, e.g., int, float, void, etc.
For instance, if we declare a Method “mathsMethod()” with a Type “int“, its Return Type must also be “int“.
returnType methodName() {
//
body of the named
method
}
methodName()
int mathsMethod(){
System.out.println("
Method Return Type must be declared!
")
}
mathsMethod()
Is it Mandatory to declare Methods with a Return Type in Method Declaration in Java?
Wiki | thetqweb