• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

output

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,


wht's o/p this?
public class Test
{
public static void main(String args[])
{
double d1 = 1.0;

double d2 = 0.0;

d1 = d1 / d2; //1

byte b = (byte) d1; //2

int i = b; //3
}
}

i think it has to give compile error.but it won't gives.it compiles correctly.


regards
Suhita
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suhita Reddy:
...i think it has to give compile error.but it won't gives.it compiles correctly...


On which line did you expect the compilation error to occur, and why? (This will help us explain what's happening.)
 
Suhita Reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on line 3
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think that assignment will give a compile error? byte, short, and char can all be converted to int without an explicit cast.

By the way "output" as a topic title is not meaningful. Please use a topic title that indicates the problem you are experiencing, such as "Is it possible to assign a byte to an int?"
[ July 08, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A byte is being assigned to an int. So, I dont think there would be a compiler error.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic