18. Which of the following is true about a constructor?
A. It must have a return type.
B. It can have the same name as the class in which it is defined.
C. It is invoked automatically when an object is created.
D. It can be called explicitly like a regular method.
Answer . C. It is invoked automatically when an object is created.
Tag . 1 Object Oriented Programming 3
20. Which of the following is used to write primitive data types to a file in Java?
A. FileOutputStream
B. BufferedWriter
C. PrintWriter
D. DataOutputStream
Answer . D. DataOutputStream
Tag . 6 Fundamentals of Programming (Java)
32. What will happen if a class does not implement all methods of an interface it implements?
A. The methods will be ignored.
B. It will cause a compile-time error.
C. The class will become abstract.
D. The interface methods will have a default implementation.
Answer . C. The class will become abstract.
Tag . 1 Object Oriented Programming 3
41. What will happen if a class does not implement all methods of an interface it implements?
A- The methods will be ignored.
B- It will cause a compile-time error.
C- The class will become abstract.
D- The interface methods will have a default implementation.
Answer . C. The class will become abstract.
Tag . 1 Object Oriented Programming 3
60. Which concept of OOP is used as a mechanism to achieve runtime polymorphism?
A- Inheritance
B- Method Overriding
C- Encapsulation
D- Method Overloading
Answer . B. Method Overriding
Tag . 1 Object Oriented Programming 3