method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

method

"A method can have one type of parameter (or parameters) and return another, different type. For example, it can take two doubles and return an int." but how can java be static language when it can return another primitive type

9th Oct 2020, 1:30 PM
holyboi
holyboi - avatar
3 Answers
+ 5
But the method return type and and the type of value returned must be the same isn't it? Statically typed languages just help you know the type of the variable you are using and that has nothing to do with the type of parameters accepted by a method and the type it returns. These languages support type checking, where you cannot assign one type to the other until and unless it is a subclass of the variable you are trying to assign to.
9th Oct 2020, 3:04 PM
Avinesh
Avinesh - avatar
+ 2
Arguments are values to be given to a methods, those are may any types any number of values.. It is completely different to return type... For ex : a function should return true on giving a required number (ex: 5). In other case shloud return false... Here return type is boolean.. But required passing values of any type.. You may pass any of like 7 or 8.9 or "hi"... For all these return false except for 5. So return type has no relationship with arguments... Hope it make sense....
9th Oct 2020, 1:55 PM
Jayakrishna 🇮🇳
+ 1
Your title and tags are not clear. To get most reasonable answer you should give more specific title and tags
9th Oct 2020, 1:44 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar