What are numeric promotions?

July 17th, 2009 by uCertify Leave a reply »

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.
  • Share/Bookmark
Advertisement

Leave a Reply

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