What are numeric promotions?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What are numeric promotions?

Rating:

Numeric promotions are used to convert the operands in a numeric expression to a common type before an operation is performed between the operands. Numeric promotion is a property of the specific definitions of the built-in operations and not a Java language feature. It is applied to the operands of an arithmetic operator. The two types of numeric promotions are as follows:

  1. Unary numeric promotion: The unary numeric promotion takes place in accordance with the following rules:

    1. If the operand is one of the following types: byte, short, or char, unary numeric promotion promotes it to a value of type int.

    2. Otherwise, no promotion takes place.

  2. Binary numeric promotion: The binary numeric promotion takes place in accordance with the following rules:

    1. If one of the two operands in a numeric expression is a primitive type double value, the other is promoted to a double value.

    2. Otherwise, if one of the two operands in a numeric expression is a primitive type float value, the other is promoted to a float value.

    3. Otherwise, if one of the two operands in a numeric expression is a primitive type long value, the other is promoted to a long value.

    4. Otherwise, both operands are promoted to int values.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.