0

Java method declaration

If we already declared a method as string i.e: public static void main(String[ ] args) How can it return/contain a variable containing of other data types?

16th Oct 2019, 4:41 AM
Muaz
Muaz - avatar
1 Odpowiedź
+ 2
return type is located before method name parameter is located between parenthesis ( ) once its declared as it is then thats it, if return value is int then it need to return int, if the parameters are string you'll need to pass string. but. you can create another method under the same name as long as they have different parameter. this is called method overloading so example below are valid. String test(){ } String test(int param1){ } String test(String param1){ } when you call them java automaticly know which method you're trying to call. for example test(3) //test with parameter int will be called test("3") //test with parameter String will be called
16th Oct 2019, 4:52 AM
Taste
Taste - avatar