Object-oriented programming Flashcards

1
Q

What is the basic building block of object-oriented programming (OOP)?
a) Object
b) Class
c) Method
d) Function

A

b) Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

b) Ensuring object properties are accessed safely

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

c) To read the value of a property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following is NOT a scope classification in Java?
a) Private
b) Protected
c) Public
d) Global

A

d) Global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

a) Classes to derive properties and methods from other classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

b) Category

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

b) To inherit from another class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

a) Hiding implementation details

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

c) By overriding an inherited method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

a) Overloading a method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is required to implement abstraction in Java?
a) Interfaces and abstract classes
b) Private constructors
c) Public properties
d) Global variables

A

a) Interfaces and abstract classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

b) It allows classes to inherit common properties and methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

a) Static polymorphism happens at compile time, dynamic at runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

a) One object taking many forms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

c) It may have a learning curve for new developers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can method abstraction be useful for different development teams?
a) It ensures all teams have access to private methods
b) It allows teams to focus only on relevant parts of the code
c) It prevents teams from working on the same codebase
d) It eliminates the need for object-oriented design

A

b) It allows teams to focus only on relevant parts of the code

17
Q

Which principle of OOP ensures that complex problems are broken down into smaller tasks?
a) Encapsulation
b) Inheritance
c) Modularity
d) Polymorphism

A

c) Modularity

18
Q

How does Java’s polymorphism allow methods to be flexible for users?
a) By allowing the same method name with different parameter types
b) By requiring only private variables
c) By preventing method overloading
d) By restricting access to certain methods

A

a) By allowing the same method name with different parameter types

19
Q

What is an advantage of code reuse in OOP?
a) It eliminates the need for inheritance
b) It prevents the use of private variables
c) Common methods do not need to be rewritten
d) Methods are hidden from other classes

A

c) Common methods do not need to be rewritten