Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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
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.
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)
0
thank you but why cant i use public calcVolume() ? i mean it is a function not a data type?