hi all,
in the code:-
class Boxandwide
{
static void go(object o)
{
Byte b2=(Byte) o;
system.out.println(b2);
}
public static void main(Strin [] args)
{
byte b=5;
go(b);
}
}
shouldnot the output be a compiler error as object reference is cast into byte,when byte class itself inherits from object class?
"....shouldnot the output be a compiler error as object reference is cast into byte,when byte class itself inherits from object class? ...."
No. You can cast Object reference to any other class..
It is not a compile error. But, it may throw a run time exception (java.lang.ClassCastException) if the that passed object is not instance of the new object.