0
What does this mean in java ?
ERROR : incompatible types: void cannot be converted to double public class otherCLASS { static void DIVIDEby2(double divide) { divide=divide/2; System.out.println(divide) ; } But when write the code like this,then there is no error public class otherCLASS { static double DIVIDEby2(double divide) { divide=divide/2; return divide ; } EDIT : main method public static void main(String[]args) { double y = 100; double w = DIVIDEby2(y); System.out.println(y); System.out.println(w); }
3 Réponses
+ 1
void method return nothing..
so,when u use the first method,and want to assign it to double w,u try to cast/convert "nothing" to a double.
since there is nothing to convert,it gives error
but the second one returns double,so it runs normally
0
how did u use that method in main?
0
@Lily Mea
Thanks.