• 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

boxing and widening doubt cant understand the logic for this program

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class BoxAndWiden
{
static void go(Object o)
{
Byte b2=(Byte)o;
System.out.println("b2");
}
public static void main(String args[])
{
byte b=5;
go(5);
}

}

reference kathy sieera book.Its first line said
that

byte b was boxed to Byte.....

now where is this boxing taking place?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are referring to Head First then you must have come across the sentence that JVM does automatic boxing on your behalf. If you are not referring that book then by now, its known to you. Yes, Java does automatic boxing (Wrap a varible inside a matching object). In this ex, when a byte value, a simple varible (5), is passed as a argument, it goes n sits in the Object type. This is the the place 'boxing' is done automatically. Then this Object is casted to Byte type object. Hope this helps.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic