Object & Classes


  1. What is the output of this program?
    class N 
    {
    int p;
    double q;
    }
    class M extends N
    {
    int r;
    }
    public class result
    {
    public static void main(String args[])
    {
    N p = new N();
    M q = new M();
    Class object;
    object = q.getClass();
    System.out.print(object.isInstance(p));
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Although class M extends class N but still a is not considered related to M. hence isInstance() returns false.


  1. What is the output of this program?
    class N 
    {
    int p;
    double q;
    }
    class M extends N
    {
    int r;
    }
    public class Result
    {
    public static void main(String args[])
    {
    N p = new N();
    M q = new M();
    Class object;
    object = q.getClass();
    System.out.print(q.equals(p));
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    false



  1. What is the output of this program?
    class N
    {
    int p;
    double q;
    }
    class M extends N
    {
    int r;
    }
    public class Result
    {
    public static void main(String args[])
    {
    N p = new N();
    M q = new M();
    Class object;
    object = q.getClass();
    System.out.print(object.getSuperclass());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    getSuperClass() returns the super class of an object. q is an object of class M which extends class N , Hence Super class of q is N. therefore class N is printed.


  1. Which of these Exceptions is thrown by loadClass() method of ClassLoader class?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    ClassNotFoundException



  1. Which of these methods returns the total number of bytes of memory available to the program?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    TotalMemory() returns the total number of bytes available to the program.