No return type in method. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

No return type in method.

So ,as you can see in 29 there is a error because the method has no return type. I dont understand why because there is return https://code.sololearn.com/cEtcBEu2kFA0/?ref=app

19th Jun 2019, 3:48 PM
Abxveä»ć€…
Abxveä»ć€… - avatar
3 Respostas
+ 1
a method which don't return a value: void + methodName() a method which returns a value: returning datatype + methodName() public AnyName() is used for constructors.
19th Jun 2019, 9:54 PM
Denise RoƟberg
Denise RoƟberg - avatar
0
Your "CalcVolume" method return a data type, more precisely, the volum (a float or a double). With this, you need to inform the type return in method's assignature like this: public float calcVolume() { int volume = height * length * breadth; return volume; } // here the method return a float public double calcVolume() { int volume = height * length * breadth; return volume; } // here, a double In your case, I guess double type return is better, but you can define as double return as well float return using Overload (thing of OOP)
19th Jun 2019, 4:43 PM
Gabriel Felix dos Santos
Gabriel Felix dos Santos - avatar
0
thank you but why cant i use public calcVolume() ? i mean it is a function not a data type?
19th Jun 2019, 5:07 PM
Abxveä»ć€…
Abxveä»ć€… - avatar