A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

1. What is the stored in the object obj in following lines of code?

box obj;
a. Memory address of allocated memory of object
b. NULL
c. Any arbitrary pointer
d. Garbage
View Answer Report Discuss Too Difficult!
Answer: (b).NULL

2. Which of these keywords is used to make a class?
a. class
b. struct
c. int
d. none of the mentioned
View Answer Report Discuss Too Difficult!
Answer: (a).class

3. Which of the following is a valid declaration of an object of class Box?
a. Box obj = new Box();
b. Box obj = new Box;
c. obj = new Box();
d. new Box obj;
View Answer Report Discuss Too Difficult!
Answer: (a).Box obj = new Box();

4. Which of these operators is used to allocate memory for an object?
a. malloc
b. alloc
c. new
d. give
View Answer Report Discuss Too Difficult!
Answer: (c).new

5. Which of these statement is incorrect?
a. Every class must contain a main() method
b. Applets do not require a main() method at all
c. There can be only one main() method in a program
d. main() method must be made public
View Answer Report Discuss Too Difficult!
Answer: (a).Every class must contain a main() method

6. What is the output of this program?
    class main_class 
    {
        public static void main(String args[])
        {
            int x = 9;
            if (x == 9) 
            { 
                int x = 8;
                System.out.println(x);
            }
        } 
    }
a. 9
b. 8
c. Compilation error
d. Runtime error
View Answer Report Discuss Too Difficult!
Answer: (c).Compilation error

7. Which of the following statements is correct?
a. Public method is accessible to all other classes in the hierarchy
b. Public method is accessible only to subclasses of its parent class
c. Public method can only be called by object of its class
d. Public method can be accessed by calling object of the public class
View Answer Report Discuss Too Difficult!
Answer: (a).Public method is accessible to all other classes in the hierarchy

8. What is the output of this program?
    class box 
    {
        int width;
        int height;
        int length;
    } 
    class mainclass 
    {
        public static void main(String args[]) 
        {        
             box obj = new box();
             obj.width = 10;
             obj.height = 2;
             obj.length = 10;
             int y = obj.width * obj.height * obj.length; 
             System.out.print(y);
        } 
    }
a. 12
b. 200
c. 400
d. 100
View Answer Report Discuss Too Difficult!
Answer: (b).200

9. What is the output of this program?
    class box 
    {
        int width;
        int height;
        int length;
    } 
    class mainclass 
    {
        public static void main(String args[]) 
        {        
            box obj1 = new box();
            box obj2 = new box();
            obj1.height = 1;
            obj1.length = 2;
            obj1.width = 1;
            obj2 = obj1;
            System.out.println(obj2.height);
        } 
    }
a. 1
b. 2
c. Runtime error
d. Garbage value
View Answer Report Discuss Too Difficult!
Answer: (a).1

10. What is the output of this program?
   class box 
   {
        int width;
        int height;
        int length;
   } 
    class mainclass 
    {
        public static void main(String args[]) 
        {        
            box obj = new box();
            System.out.println(obj);
        } 
    }
a. 0
b. 1
c. Runtime error
d. classname@hashcode in hexadecimal form
View Answer Report Discuss Too Difficult!
Answer: (d).classname@hashcode in hexadecimal form

Page 1 of 16