Object & Classes


  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    Object o = new Object();
    System.out.print(o.getClass());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    class java.lang.Object


  1. Which of these methods returns the class of an object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    getClass()



  1. Which of these classes encapsulate runtime state of an object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Class


  1. What is the output of this program?

    class N
    {
    int K;
    int L;
    N()
    {
    K = 1;
    L = 2;
    }
    }
    public class Result
    {
    public static void main(String args[])
    {
    N object = new N();
    System.out.print(object.toString());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    toString() is method of class Object, since it is superclass of every class, every object has this method. toString() returns the string associated with the calling object.



  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    Object object = new Object();
    System.out.print(object.getclass());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Result.java:6: error: cannot find symbol
    System.out.print(object.getclass());
    ^
    symbol: method getclass()
    location: variable object of type Object
    1 error
    output: Compilation error