Object-Oriented Programming Flashcards
7 cards from real CodeSignal Technical Assessment practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Object-Oriented Programming flashcards as text
What is encapsulation in object-oriented programming?
Answer: Bundling data and methods within a class while restricting direct access to internal state
Encapsulation bundles data and the methods that operate on it into a single unit (class) while hiding internal state from outside access.
Which keyword is used in Java, C++, and JavaScript to create a new instance of a class?
Answer: new
The `new` keyword allocates memory and invokes the constructor to create a new object instance in most OOP languages.
What is inheritance in object-oriented programming?
Answer: A mechanism where one class acquires the properties and methods of another class
Inheritance allows a child (subclass) to acquire attributes and behaviors from a parent (superclass), enabling code reuse and hierarchical classification.
What is a constructor in OOP?
Answer: A special method automatically called when a new object is created
A constructor is a special method automatically invoked upon object creation, used to initialize the object's fields and set its initial state.
What does the `this` keyword (or `self` in Python) refer to inside an instance method?
Answer: The current instance of the class on which the method is called
`this` / `self` is a reference to the current object instance, allowing methods to access and modify the object's own properties.
Which OOP principle means different objects can respond to the same method call in their own specific way?
Answer: Polymorphism
Polymorphism allows objects of different types to be treated through a common interface, with each type providing its own implementation of the method.
Which of the following best describes an abstract class?
Answer: A class that cannot be instantiated directly and may contain abstract methods subclasses must implement
An abstract class cannot be instantiated on its own; it serves as a blueprint that concrete subclasses extend and whose abstract methods they must implement.