GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes  boxing and widening doubt  cant  understand the logic for this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark " boxing and widening doubt  cant  understand the logic for this program" Watch " boxing and widening doubt  cant  understand the logic for this program" New topic
Author

boxing and widening doubt cant understand the logic for this program

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

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?

http://www.lifesbizzare.blogspot.com || OCJP:81%
Sandesh Hiremath
Greenhorn

Joined: Dec 18, 2009
Posts: 5
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.

 
GeeCON Prague 2014
 
subject: boxing and widening doubt cant understand the logic for this program