The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes casting Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "casting" Watch "casting" New topic
Author

casting

chetan nain
Ranch Hand

Joined: Jun 21, 2000
Posts: 159
code:
public class AnotherDirtyOne
{
private final int i =10;
private byte k = i;
}

compiles cleanly, but the code
public class AnotherDirtyOne
{
int i =10;
byte k = i;
}
gives compiler error requiring explicit cast for byte k=i
why does code 1 compile correctly?

Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Chetan,
I think Ajith gave a very good explanation here:
http://www.javaranch.com/ubb/Forum24/HTML/003617.html
Hope this helps.
Stephanie
 
 
subject: casting
 
Threads others viewed
Can we have forward refrencing with final instance variable
byte to int ?
how this works?
casting
why we do not require explicit casting at line no.3
IntelliJ Java IDE