This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anyone tell the result of this code.

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can anyone tell me, why following code prints float,float.

a. Prints: float,float b. Prints: float,double
c. Prints: double,float d. Prints: double,double
e. Compile-time error f. Run-time error
g. None of the above

Answer is float, float
[ June 23, 2005: Message edited by: Srinivasa Raghavan ]
 
saran sadaiyappan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since is float is more specific than double it prints "float,float".Specific in the sense that float can take only float values...whereas double can take both float and double.

Hope I am right.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok So, if i add one more method that takes long, like the one below it should print long,long. Thanks saran.


static String m(long i) {return "long";}
 
Sangita Mishra
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it will print long, long. As both int and long canbe converted to long and long is more specific than float and double.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic