Quiz Week 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

QUIZ WEEK 4

1. When programming in an object-oriented language, what does inheritance allow?


A) An independent function to execute
B) A class to share members defined from another function
C) A class to share members defined from another class
D) A method to override all other methods
2. How is inheritance defined?
A) Calling an unrelated function
B) Calling an existing or derived class
C) Sharing methods only between interfaces
D) Creating a new member within a single class
3. What term is used for the class from which members are inherited?
A) Child Class
B) Derived Function
C) Base Class or Super Class
D) Interface Method
4. Which statement best describes a derived class?
A) It inherits properties only from interfaces.
B) It cannot inherit any properties.
C) It inherits properties from an existing base or super-class.
D) It serves as a base for other classes without inheriting any properties.
5. What keyword is used to define subclasses in Java?
A) subclass B) extends C) implements D) inherits
6. Can a subclass inherit private members of its superclass directly?
A) Yes, always.
B) No, it cannot.
C) Only if they are static.
D) Only through public methods of superclass.
7. How can a subclass access members with the same name as those in its superclass?
A) By redeclaring them.
B) Using ‘super’ keyword.
C) It is not possible to have members with the same name.
D) By using ‘this’ keyword.
8. What does the ‘super’ keyword refer to?
A) The current class instance
B) The direct superclass of a class
C) Any class that is being extended
D) The main method of Java
9.What type of inheritance allows a subclass to inherit from only one base class?
A) Multiple inheritance
B) Multilevel inheritance
C) Single inheritance
D) Hierarchical inheritance
10. What must a subclass constructor do with data members inherited from its superclass?
A) Ignore them
B) Initialize them using its own methods
C) Initialize them by calling the superclass constructor
D) Delete them before re-creating them
11. How should you call a superclass constructor within a subclass constructor?
A) At any point within the subclass’s body
B) After all other statements have been executed
C) Using superclass(arguments);
D) By using super(arguments); as the first statement of the subclass’s constructor
12. What will happen if there is no explicit call to a superclass’s default constructor within
a subclass’s constructor?
A) The program will not compile.
B) The compiler will automatically invoke all default constructors of parent classes if such
classes have default constructors.
C) The compiler will throw an error at runtime.
D) The data members inherited from parent classes will remain uninitialized.
13. In object-oriented programming, what does the term “method overloading” refer to?
A) Defining multiple methods with different names but the same functionality.
B) Defining multiple methods with the same name and identical argument lists.
C) Defining multiple methods with the same name but different argument lists.
D) Removing existing methods and replacing them with new ones.
14. When overloading a method, what can be different?
A) Method name B) Return type C) Access scope D) Argument list type or order
15. Can two overloaded methods have the same return type?
A) Yes, as long as their argument lists differ.
B) No, they must have different return types.
C) Yes, if they are defined in different classes.
D) No, because it will cause a compilation error.
16. What does polymorphism depend on in a referencing context?
A) The data type B) The inheritance relations C) The method name D) The class object
17. Polymorphism allows multiple methods with the same name in the same class or in
classes with what kind of relationship?
A) No relationship B) Inheritance relations C) Interface implementations D) Method overloading
18. Which are the two mechanisms of polymorphism mentioned for Java?
A) Overriding method and Overloading method
B) Inheritance and Encapsulation
C) Abstract classes and Interfaces
D) Static and Dynamic binding
19. What does overriding methods help improve?
A) Code complexity B) Code redundancy C) Code extensibility D) Code efficiency
20. Adding new features without affecting old components is an advantage of which aspect
of polymorphism?
A) Overriding methods B) Overloading methods C) Inheritance relations D) Encapsulation
21. What does method overriding allow in object-oriented programming?
A) Allows a subclass to ignore methods from its superclass.
B) Allows a subclass to provide a specific implementation of an existing superclass method.
C) Allows a subclass to prevent further inheritance.
D) Allows a superclass to access methods from its subclass.
22. When overriding a method, what should be true about its access scope?
A) It should be more restrictive than the base class.
B) It should be less restrictive than any other unrelated class.
C) It cannot change from private to public.
D) It should not be more restrictive compared to the base class.
23. How can you invoke an overridden method of a superclass in Java?
A) By calling ‘super.methodName()’.
B) By calling ‘this.methodName()’.
C) By calling ‘methodName()’.
D) By calling ‘base.methodName()’.
24.What is late binding in object-oriented programming?
A) Binding source code before compilation.
B) Linking source code at runtime.
C) Assigning values during program execution.
D) Overriding methods after program execution.
25. The ability of a programming language to process objects differently depending on
their type is:
A. Inheritance
B. Overloading
C. Polymorphism
D. Abstraction
E. Encapsulation
F. Overriding
26. In object-oriented programming, which of the following is not a characteristic of
method overriding?
A. The override method has a different signature than the overridden method.
B. Access scope should not be narrower than the base class method.
C. It involves re-defining methods of the super-class in the sub-class.
27. In the context of method overriding, what does “super.xxx()” represent?
A. It invokes the overridden method xxx() in the parent class.
B. It defines a new method xxx() in the subclass.
C. It is a syntax error and not applicable.
26. Which of the following is NOT a mechanism of polymorphism in Java?
A. Overloading method
B. Overriding methods
C. Inheritance
D. Encapsulation
27. What does polymorphism help improve?
A. Code organization only
B. Extensibility only
C. Both code organization and extensibility
D. Neither code organization nor extensibility
28. Which statement about polymorphism is correct?
A. It allows multiple methods with different names in the same class.
B. It depends on referencing context.
C. It restricts code organization.
D. It affects old components when adding new features.
29. Which of these statements about Polymorphism is incorrect?

A. Polymorphism allows multiple methods with the same name in different classes.
B. Polymorphism is dependent on referencing context.
C. Overloading and overriding are mechanisms of polymorphism.
D. Polymorphism hinders code organization.
30. What is the process of decomposing a problem into a set of modules to reduce
overall complexity called?
A) Modularization B) Hierarchy C) Aggregation D) Generalization
31. Which principle represents the relationship where a “Rose is a flower”?
A) Inheritance (IS-A) B) Aggregation (HAS-A) C) Generalization D) Encapsulation
32. What is the purpose of function overloading?
A) To create unrelated methods with the same name
B) To allow multiple methods with the same name but different parameters
C) To enhance code reusability
D) To improve performance
33. What does the term “Compile Time Overloading” refer to?
A) The process of resolving function overloading at compile time
B) The dynamic binding of overloaded methods
C) The use of polymorphism
D) The optimization of method calls
34. Which design principle promotes code reusability by allowing a class to inherit
attributes and methods from another class?
A) Encapsulation B) Abstraction C) Inheritance D) Polymorphism
35. Can objects of abstract classes be instantiated? A) Yes B) No
36. What does the process of “Folding Link Attributes into Classes” aim to achieve?
A) Reducing the number of classes in a system
B) Improving encapsulation
C) Enhancing code readability
D) Simplifying the design
37. Which principle ensures that a subclass can be used interchangeably with its
superclass?
A) Liskov Substitution Principle (LSP)
B) Interface Segregation Principle (ISP)
C) Dependency Inversion Principle (DIP)
D) Open-Closed Principle (OCP)
38. What is the term for wrapping data and code into a single unit?
A) Abstraction B) Encapsulation C) Polymorphism D) Inheritance
39. In Java, when a method in a subclass overrides a method in the superclass, what
happens to static variables in the superclass?
A) Static variables in the superclass are not affected by method overriding.
B) Static variables in the superclass are overridden by the corresponding variable values in the
subclass.
C) Static variables in the superclass cannot be overridden.
D) Static variables in the superclass can only be overridden using the super keyword.
40. Which of the following is true ?
A. A class can inherit from many different classes by using the extends
B. A class can inherit from many other interfaces by using the extends
C. An interface can inherit from multiple interfaces by using the extends
D. All statements are false

You might also like