Skip to content
Related Articles
Open in App
Not now

Related Articles

Java | Data Types | Question 3

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

Predict the output of the following program.




class Test
{
    public static void main(String[] args)
    {
        Double object = new Double("2.4");
        int a = object.intValue();
        byte b = object.byteValue();
        float d = object.floatValue();
        double c = object.doubleValue();
  
        System.out.println(a + b + c + d );
  
    }
}

(A) 8
(B) 8.8
(C) 8.800000095367432


Answer: (C)

Explanation: Arithmetic conversions are implicitly performed to cast the values to a common type. The compiler first performs integer promotion. If the operands still have different types, then they are converted to the type that appears highest in the hierarchy.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!