aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Iimplicit cast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Iimplicit cast" Watch "Iimplicit cast" New topic
Author

Iimplicit cast

Fox Hu
Ranch Hand

Joined: Jan 23, 2003
Posts: 49
byte b=127;
byte c=126;
byte d=b-c;
In the third line the compiler complains .
It seams that the result is casted to int implicitly when two number calculate, but why?
And are there any other cases do the implicit cast appears ?
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
but it is compiled!


a beginner in java
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
http://www.coderanch.com/t/240873/java-programmer-SCJP/certification/Casting


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Paula Jiang
Greenhorn

Joined: Feb 15, 2003
Posts: 15
From Kathy/Bert 's book, page 148-149: "the result of an expression involving anything int-sized or smaller is always an int. In other words, add two bytes together and you'll get an int."
So the compiler will complain that it can't convert int to byte, you need to explicit case to byte.


SCJP2 1.4 (96%) SCWCD(96%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iimplicit cast