File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arithmetic promotion 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 "Arithmetic promotion" Watch "Arithmetic promotion" New topic

Arithmetic promotion

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481

in line 1,found int ;required byte error is displaying.but i thought

How come found int;required byte error is coming .i just expected found Double,required byte.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Since the types of the operands are byte, both are promoted to int before the operation.
Dustin Johnson

Joined: Nov 14, 2006
Posts: 22
K&B Book Pg. 182...

"...but more importantly, the result of an expression involving anything int-sized or smaller[i.e. byte] is always an int"

I believe the code is converting them both into int sized values automatically to try and perform the mathematical operation.
[ March 08, 2007: Message edited by: Dustin Johnson ]

SCJA 86%<br />SCJP 5.0 98%<br />SCWCD 1.4 79%<br />SCBCD 5.0 83%<br />--------------------------------<br />"I drank what???" - Socrates
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Don't ever write a program with variable names like that in your real working life. If you are not fired, leave immediately.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Bert Bates

Joined: Oct 14, 2002
Posts: 8898

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I agree. Here's the link:
subject: Arithmetic promotion
jQuery in Action, 3rd edition