void is the java keyword that indicates that a method has no return type.
void is the java keyword that indicates that a method has no return type.
name the java keyword that indicates that a method has no return type?
void
return type









































in computer programming, the return type (or result type) defines and constrains the data type of the value returned from a subroutine or method. in many programming languages (especially statically-typed programming languages such as c, c++, java) the return type must be explicitly specified when declaring a function.









































in the java example:









































the return type is "int". the program can therefore rely on the method returning a value of type "int". various mechanisms are used for the case where a subroutine does not return any value, e.g., a return type of "void" is used in some programming languages:
return type
more specifically, covariant (wide to narrower) or contravariant (narrow to wider) return type refers to a situation where the return type of the overriding method is changed to a type related to (but different from) the return type of the original overridden method. the relationship between the two covariant return types is usually one which allows substitution of the one type with the other, following the liskov substitution principle. this usually implies that the return types of the overriding methods will be subtypes of the return type of the overridden method. the above example specifically illustrates such a case. if substitution is not allowed, the return type is invariant and causes a compile error.
covariant return type