• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

What is the mystery ?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run the following program in text pad (I have jdk1.1.7(IBM)on NT) I gets O/P as 10 & when the same program is run with VAJ3.0 on NT I gets O/P as 10.0
Can any one explain the mystery ?
If I have following choices then what I should I pick for such type of questions ?
a) Compiler error
b) Runtime exception
c) 10
d) 6.0
e) 10.0
class X {
public static void main(String[] a) {
System.out.println(9 > 8?10:6.0);
}
}

Cheers
Ashish
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that there have already been several useful responses to your same question over at Marcus' site. But perhaps others can add something as well...
[This message has been edited by Jim Yingst (edited December 28, 2000).]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear asheesh
See basically your o/p is in the integer form. While the Sop (System.out.println) takes a String class object as it's parameter or in simpler words u must pass on a string value to Sop method. Now when the answer to the argument passed is evaluated it comes out to be 10. now the JVM finds that the answer is in the integer format & not the compiler format. to this the interpreter calls the toString() method or the valueOf() method. this converts 10 to "10" & gives the o/p. but dear acc to me it depends on the valueOf() method. on one ocassion it might have called the valueOf(int) & on the other ocassion iot might have called valueOf(double) & given th o/p as 10.0
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Asheesh,
I think the aswer would be 10.0. 10 is promoted to a double since the operation involves 6.0, which is a double.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic