Menu
Topics Index
...
`

Long Value


If you need explanation Read this topic

If you need Answer Take test on this topic

Long Value
What will be the output of the following program?
public class UsingLong {
    public static void main(String args[]) {
        Double dub = new Double("12.57689");
        Float flo = new Float("12.56f");
        long lon = dub.longValue();
        long ln = flo.longValue();
        System.out.print(lon + ", " + ln);
    }
}

A. 12.57689, 12.56
B. 12.57689, 12.0
C. 12.0, 12.0
D. 12, 12
E. Compilation Error or Runtime Error
Topic: Java Double Class And Java Float Class

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 D as longValue() method  returns the value of this Long as a long value.

Posted by Ramya Reddy Addulla    2014-10-15 12:38:58


Answer is D as long datatype belong to the integer family and would thus return an long int.

Posted by Sheetal Agrawal    2014-10-15 13:03:40


Ans is D...
here Double,Float  are wrapper classes which is used to wrap the primitive into Object form...these classes present in java.lang package

here we are passing the values lik an String constructors in these classes wil parse it into double value...throws NumberFormat Exception if the num is not able to parse

Ex:new Double("Meritcampus");
Ex:new Float("Meritcampus");

longValue() is an method which converts double value into long value..internal typecasting wil occur..in both Double and Float classes

Posted by Uday Kumar    2014-10-15 15:01:55


ans d.

the process of encapsulating a value with in a object is called boxing.

in this program double and float used this method.

these are called as wrappers.it is used to treat primitive value as an object.

Number class is an abstract class that serves as the superclass for all of the classes that provide object wrappr for primitive numeric values byte,int,float,double, short, long.

the number class defins 6 methods intValue(),bytevalue(),shortvalue(),longvalue(),floatvalue(),double value().
this means Number object can be fetched as an byte,short, int,long, double, float value without regard for its actual class.

in this program long values are fetched by using double and float subclass.

so both returns 12 long value from double and float object.

this method is called as un-boxing.
boxed object extracted from type wrappers

Posted by Maheshwari Natarajan    2014-10-15 17:10:59


This dose is now closed and the winners are Ramya Reddy Addulla,  for 'First Correct Comment', Maheshwari Natarajan,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Ramya Reddy Addulla. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-16 04:22:24


© meritcampus 2019

All Rights Reserved.

Open In App