+ 1

Is it really important to declare a method as int type if it has two parametres of type int like: static int hi()

30th Mar 2018, 5:02 AM
Devansh Gupta
Devansh Gupta - avatar
4 Answers
+ 2
It is not necessary to update methods in this way. The type of data is specified in those cases when you need to return something after the method is executed. If this is not necessary you can write just void. If the method should return something, then you must specify the data type.
30th Mar 2018, 5:30 AM
Aidos Zhakupov
Aidos Zhakupov - avatar
+ 2
Aidos Zhakupov answer is good, i want to add: Maybe you wonder why you have to declare int as a return type in languages like Java. It is because of something called "typesafety". By declaring a return type the compiler of java can force you to return a specific type that you declared in your method, by throwing an exception. (and when somebody else reads your code, that person knows what your method will return in terms of type)
30th Mar 2018, 5:47 AM
***
*** - avatar
+ 1
declaring a method as int or float or any other data type depends on the return value of that method
30th Mar 2018, 5:07 AM
Prateek Narang
Prateek Narang - avatar
0
Is it important to keep track of the return type and to declare A method using the data type
30th Mar 2018, 5:13 AM
Devansh Gupta
Devansh Gupta - avatar