Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
public class IntConversion {
    public static void main(String args[]) {
        Float f1 = new Float(25.0f);
        int k = f1.intValue();
        Byte b = (byte) f1.intValue();
        System.out.print(k + " " + b);

A. 25 25.0
B. 25 25
C. 25 25.0f
D. Compilation Error or Runtime Error
Topic: Java FileWriter

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is we have the Wrapper class concept..
here we create the instance for the Float by passing the we write f to tell the system treat this num as float not double bcz every decimal number in java by default is Double...

here we create the instance of Flaot by passing the we are calling intValue() method on that object so it will return the 25 as int primitive..this is method will returns the object into primitives..
next we are calling sam method so it will return 25 and we are type casting that number into it will print 25 25

Posted by Uday Kumar    2014-12-17 12:40:12

ans b. conversion of primitive data types into its equivalent Wrapper type is known as boxing and opposite operation is known as using Float wrapper class float value 25.0f get wrapped into the object.thn auto boxing is used to fetch the int value from float object.intValue() this method returns int primitive value from fetching float object.this is assigned to k.thn again int value get from float object by using intValue() this int primitive value is assigned to byte variable. here source value range bigger thn destination byte range .that is why here explicit type convention is 25 is also within the range of byte.bcz it is small number. sop print int and byte value as 25

Posted by Maheshwari Natarajan    2014-12-17 17:45:15

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Maheshwari Natarajan,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-18 04:40:39

© meritcampus 2019

All Rights Reserved.

Open In App