Midterm Exam OOP
Midterm Exam OOP
Professional Elective 1
Midterm Exam
2022-2023
Name: ________________________ Course & Year: _____________ Date: ____________ Score: ___
Test I: Multiple Choice
Direction: Read each question carefully. Choose the letter of the correct answer and write it in the provided space.
class Vehicle {
String type = "Vehicle";
}
A. Vehicle
B. Car
C. null
D. Compilation error
7. What happens if a class in Java does not explicitly extend another class?
A. When a subclass method has the same name and signature as a static method in the superclass
B. When an instance method in a subclass has the same signature as a static method in the superclass
C. When a private method of the superclass is not visible in the subclass
D. When a method in a superclass is declared final
11. In Java, what happens if a subclass does not explicitly call a superclass constructor?
class Parent {
public Parent() {
System.out.println("Parent constructor");
}
}
A. Child constructor
B. Parent constructor
C. Parent constructor, then Child constructor
D. Compilation error
14. What happens when a method in a subclass has the same name and signature as a method in its superclass?
16. If a class contains at least one abstract method, the class must be declared as:
A. Static
B. Final
C. Abstract
D. Concrete
class A {
public void display() {
System.out.println("Display A");
}
}
class B extends A {
public void display() {
System.out.println("Display B");
}
}
A. Compilation error
B. "Display A" will be printed
C. "Display B" will be printed
D. Runtime exception
20. Which of the following will prevent a method from being overridden in Java?
24. What is the purpose of the super() keyword inside a subclass constructor?
25. What happens if a class inherits from a class with a final method?
26. Encapsulation in OOP is the practice of bundling data and methods that operate on the data into a single unit.
27. Inheritance allows a class to inherit properties and methods from another class.
28. Polymorphism means that an object can take on multiple forms.
29. Abstraction in OOP is about hiding implementation details and showing only the functionality.
30. A constructor in Java must have the same name as the class and can have a return type.
31. In OOP, an abstract class cannot be instantiated but can contain fully implemented methods.
32. A Java interface can have constructors and instance variables.
33. Method overloading allows multiple methods in the same class to have the same name but different parameters.
34. Method overriding is used when a subclass provides a specific implementation of a method already defined in its
parent class.
35. In OOP, static methods belong to the class, not to any specific instance.
36. The this keyword in Java refers to the current object of a class.
37. An abstract class can implement multiple interfaces in Java.
38. A final class in Java can be subclassed.
39. In OOP, a class can have multiple constructors but only one destructor.
40. A singleton class ensures that only one instance of the class can be created during the program's lifetime.
41. Inheritance supports the "is-a" relationship in OOP.
42. Encapsulation ensures that an object's internal state can only be changed through its methods.
43. In Java, an interface can extend multiple other interfaces.
44. An abstract method in Java is a method that has no implementation and must be overridden in derived classes.
45. The super keyword in Java is used to refer to the parent class's constructor or methods.
46. Static methods can access instance variables directly.
47. Overloading and overriding are examples of polymorphism in OOP.
48. A class marked as abstract in Java must have at least one abstract method.
49. Multiple inheritance is supported in Java through the use of classes.
50. OOP principles are only applicable in object-oriented programming languages.
Answer Key
1. B
2. B
3. C
4. C
5. B
6. C
7. A
8. B
9. C
10. A
11. B
12. C
13. B
14. B
15. A
16. C
17. A
18. B
19. B
20. A
21. C
22. D
23. C
24. B
25. C
26. True
27. True
28. True
29. True
30. False
31. True
32. False
33. True
34. True
35. True
36. True
37. True
38. False
39. True
40. True
41. True
42. True
43. True
44. True
45. True
46. False
47. True
48. False
49. False
50. False