โ† All HACKERRANK Flashcard Decks

Object-Oriented Programming Basics Flashcards

7 cards from real HACKERRANK 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 Basics flashcards as text
  1. Which method is automatically called when an object is created from a class?

    Answer: __init__

    __init__ is the initializer method called automatically after object creation to set up instance attributes.

  2. What does the 'self' parameter in an instance method refer to?

    Answer: The current instance of the class

    'self' refers to the current instance of the class, allowing access to instance attributes and methods.

  3. What will the following code output? class Dog: def __init__(self, name): self.name = name d = Dog('Rex') print(d.name)

    Answer: Rex

    d.name accesses the instance attribute 'name' set during __init__, which was given the value 'Rex'.

  4. Which keyword is used to inherit from a parent class in Python?

    Answer: The parent class is passed in parentheses

    Python uses class ChildClass(ParentClass): syntax โ€” the parent class name is placed in parentheses after the child class name.

  5. What is a class attribute vs an instance attribute?

    Answer: Class attributes are shared by all instances; instance attributes are unique per object

    Class attributes are defined at the class level and shared across all instances, while instance attributes are set per object via self.

  6. Which built-in function returns the class (type) of an object?

    Answer: type()

    type(obj) returns the class of obj; e.g., type(42) returns .

  7. What does 'encapsulation' mean in OOP?

    Answer: Data and methods are bundled together, with controlled access

    Encapsulation bundles data and the methods that operate on it inside a class, hiding internal details from outside code.

Object-Oriented Programming Basics Flashcards โ€” HACKERRANK Study Cards with Answers