Methods


  1. Which of these method return a pseudorandom number?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    random()


  1. Which of these class contains all the methods present in Math class?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    SystemMath class defines a complete set of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is guaranteed to generate precisely identical results across all Java implementations.



  1. What is the output of this program?
    public class Result
    {
    public static void main(String args[])
    {
    Double num0 = new Double(260.0062);
    Double num1 = new Double(260.0062123456);
    try
    {
    int p = num1.compareTo(num0);
    System.out.print(p);
    }
    catch(ClassCastException e)
    {
    System.out.print("Exception");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    num1.compareTo() methods two double values, if they are equal then 0 is returned and if not equal then 1 is returned, here 260.0062 and 260.0062123456 are not equal hence 1 is returned and stored in p.


  1. What is the output of this program?
    public class Result
    {
    public static void main(String args[])
    {
    Double num = new Double(260.00625023);
    float p = num.floatValue();
    System.out.print(p);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    floatValue() converts the value of wrapper i into float, since float can measure till 5 places after decimal hence 260.00626 is stored in floating point variable p.



  1. What is the output of this program?
    public class Result
    {
    public static void main(String args[])
    {
    Double num = new Double(260.062);
    int p = num.intValue();
    System.out.print(p);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    num.intValue() method returns the value of wrapper i as a Integer. num is 260.062 is double number when converted to an integer data type its value is 260.