This week's book giveaway is in the Android forum.
We're giving away four copies of Create an Uber Clone in 7 Days: Build a real world full stack mobile app in Java and have Shai Almog on-line!
See this thread for details.
Win a copy of Create an Uber Clone in 7 Days: Build a real world full stack mobile app in Java this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anyone tell the result of this code.  RSS feed

 
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 ]
 
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";}

 
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.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!