No return type in method. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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 ответов
+ 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