Object-oriented programming Flashcards
What is the basic building block of object-oriented programming (OOP)?
a) Object
b) Class
c) Method
d) Function
b) Class
In OOP, what is encapsulation primarily responsible for?
a) Allowing objects to inherit properties
b) Ensuring object properties are accessed safely
c) Hiding method implementations
d) Overloading methods
b) Ensuring object properties are accessed safely
What is a getter method used for in Java?
a) To modify the value of a property
b) To delete a property
c) To read the value of a property
d) To create a new object
c) To read the value of a property
Which of the following is NOT a scope classification in Java?
a) Private
b) Protected
c) Public
d) Global
d) Global
What does inheritance allow in OOP?
a) Classes to derive properties and methods from other classes
b) Methods to modify private variables
c) Objects to hide their data
d) Classes to override methods
a) Classes to derive properties and methods from other classes
In the inheritance example, which property is common across all products in the online store?
class Product { private String name; private String category; private BigDecimal price; // getters and setters }
public class Movie extends Product { private String title; private int lengthInMinutes; // getters and setters }
a) Title
b) Category
c) Length in minutes
d) Weight
b) Category
What is the purpose of the ‘extends’ keyword in Java?
a) To define a method
b) To inherit from another class
c) To declare a variable
d) To create an object
b) To inherit from another class
What does abstraction in OOP help with?
a) Hiding implementation details
b) Modifying object properties directly
c) Preventing code reuse
d) Eliminating the need for classes
a) Hiding implementation details
How can dynamic polymorphism be achieved in Java?
a) By creating multiple constructors
b) By using abstract classes
c) By overriding an inherited method
d) By creating private variables
c) By overriding an inherited method
Which of the following is an example of static polymorphism in Java?
a) Overloading a method
b) Overriding a method
c) Creating a private variable
d) Inheriting a class
a) Overloading a method
What is required to implement abstraction in Java?
a) Interfaces and abstract classes
b) Private constructors
c) Public properties
d) Global variables
a) Interfaces and abstract classes
In the concept of OOP, what is a key advantage of using inheritance?
a) It hides methods from other classes
b) It allows classes to inherit common properties and methods
c) It prevents code reuse
d) It eliminates the need for methods
b) It allows classes to inherit common properties and methods
What is the key difference between static and dynamic polymorphism?
a) Static polymorphism happens at compile time, dynamic at runtime
b) Dynamic polymorphism uses multiple constructors
c) Static polymorphism overrides methods, dynamic overloads methods
d) Dynamic polymorphism does not allow method overloading
a) Static polymorphism happens at compile time, dynamic at runtime
What does the term polymorphism mean in OOP?
a) One object taking many forms
b) A method overriding a private variable
c) Two objects with different properties
d) Hiding object methods from other classes
a) One object taking many forms
What is a disadvantage of object-oriented programming?
a) It reduces modularity
b) It complicates code reuse
c) It may have a learning curve for new developers
d) It eliminates collaboration between teams
c) It may have a learning curve for new developers