What happens when you assigned a 'double' value to
a 'String'?

Answer Posted / pankaj

hi,
toString() method will also not work here.

double d=10.5;
String str= d.toString();

E:\Programs>javac conversionTest.java
conversionTest.java:6: double cannot be dereferenced
String str= d.toString();
^
1 error


The only way I found is as below and is working fine.

double d=10.5;
String str= ""+d+"";
System.out.println(str);

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does a void function return?

551


Why does java not support operator overloading?

660


When throws keyword is used?

584


What is array initialization in java?

495


Explain about main thread in java?

613






What is a wrapper method?

537


What is the history of java?

548


What are triggers in DB? Explain their types. How do they work?

628


Explain the difference between jdk, jre, and jvm?

595


How do you test a method for an exception using junit?

535


What does flag mean in java?

544


Differentiate between class and structure.

633


Why is java multithreaded?

542


what is the purpose of using rmisecuritymanager in rmi?

568


Can we have a method name same as class name in java?

583