Monday, 2 April 2012

MCQ- Class and Interface


MCQ - Class and Interface

1. classes are useful because they
A. permit data to be hidden from other classes
B. can closely model objects in the real world
C. brings together all aspects of an entity in one place 
D. all of the above.


2. Which of the following is the correct statement to create an object of Data class?
A. Data d=new object();
B. Data d=new Data();
C. Data d()=new Data();
D. Data d()=new Data();

3. The new keyword is used to ____

A. call a method of a class
B. Allocate memory to an object
C. Release memory of an object
D. none of above

4. A constructor is a special type of_____
A. class
B. variable
C. method
D. object

5. A default constructor ______
A. has no return type
B. has no argument
C. has one argument
D. has one argument but no return type.
6. To specify default access to a variable or a method ___ keyword is used
A.public
B. private
C. default
D. none of above

7. The .dot operator connects the following two entities :
A. a class member and a class object
B. a class object and a class
C. a class and a member of that class
D. a class object and a member of that class

8. When a variable is declared as static , _____
A. It is automatically initialized before an object of its class is created.
B. It becomes constant
C. Its value is changed every time an object of its class is created.
D. It becomes public.

9. Before doing garbage collection , _____ method is called :
A. main()
B. finalize()
C. final()
D. collect()

10. Inheritance means______
A. ability to take more than one form
B. data hiding
C. ability to use properties of another class
D. wrapping up of data and methods
11.To inherit from class ___ keyword is used.
A. inherit
B. extends
C. uses
D. implements

12.Java does not support ____ inheritance
A. multilevel
B. multiple
C. Hierarchical
D. Single
13. When method is overridden , then by subclass object which class ‘s method is called
A. super class
B. subclass
C. both
D. none

14. When class is declared as abstract , then ____
A. Its object can not be created
B. Its subclass can not be created
C. It can not inherit any class

D. It can not have methods

15. When a class is declared as final , then ____
A. It can not be inherited
B. It must be inherited
C. Its object can not be created

D. none of these

16.___ keyword is used to refer to the current object
A. super
B. this
C. new
D. volatile

17. ____ are automatically called when an object is destroyed
A. collectGarbage()
B. Destructor()
C. finalize()
D. final()

18. Overloaded methods ____
A. are a group of methods with the same name
B. have the same number and type of arguments
C. make life simpler for programmer
D. may fail unexpectedly due to stress.

19.A recursion occurs when ___
A. a constructor calls a method
B. A method calls itself
C. a method calls aother method
D. A constructor calls another constructor.

20. super keyword can be used to _____
A. call super class ‘s constructor
B. access super class ‘s member
C. both a and b
D. none of the above


Answers:

1
- D
2
- B
3
- B
4
- C
5
- B
6
- D
7
- D
8
- A
9
- B
10
- C
11
- B
12
- B
13
- B
14
- B
15
- A
16
- B
17
- C
18
- A
19
- B
20
- C



Interface

1.The methods of interface are ______ by default.
A. abstract
B. static
C. final
D. none of these

2. An interface can be declared using ______ keyword
A. class
B. interface
C. interfaces
D. implements

3. To implements an interface _____ keyword is used
A. extends
B. interface
C. implements

D. implement
4. The variables of interfaces are _____ by default
A. final
B. static
C.final and static
D. all of above

5. A class can implements _____ interfaces
A. only one
B. one or more than one
C. maximum two
D. minimum two

6. A method implementation of an interface must be declared as _____
A. private
B. default access
C. public
D. protected

7. An interface contains _____
A. The method definitions
B. The method declaration
C. Method declaration and definition
D. none of these

8. A class implements an interface but does not override all the methods of interface then ______
A. It should be declared as abstract class
B. It should be declared as final class
C. It must override all the methods of interface
D. none of these

9. Which of the following is true
A. A class can extend more than one class
B. A class can implement only one interface
C. A class can extend only one class and can implements more than one interface
D. A class can extend only one class and can implements only one interface

Answers :

1
- A
2
- B
3
- C
4
- C
5
- B
6
- A
7
- B
8
- A
9
- C






Posted By : Ruchita Pandya

No comments:

Post a Comment