Originally posted by Radiya Sojitrawala:
Is this correct and if yes how/why? Why would we not need 'new' to allocate memory to d?
Double d = Double.valueOf("3.14");
thanks
radiya
Hi Radiya,
Well, actually what we are doing is using the inbuilt function, valueOf(), of the Wrapper class Double to convert a
String representation of a double number(3.14) back into double.
When we say Double.valueOf("3.14"), it means that we have a String argument "3.14" which we wish to convert into a Double Wrapper Object as 3.14.
This function will return an object of type Double which will be assigned to d. Hence d has to be of type Double too. That's why we do not need the new operator.