2.1 Creating and Using Objects

Cards (180)

  • What are the three key concepts in object-oriented programming (OOP)?
    Encapsulation, inheritance, polymorphism
  • What do public methods provide in encapsulation?
    Clear interface
  • What type of structure does inheritance create in code organization?
    Hierarchical structure
  • What is an object in object-oriented programming?
    Self-contained entity
  • What defines the behavior of an object in OOP?
    Methods
  • What is a class in object-oriented programming?
    Blueprint for objects
  • Data hiding in encapsulation protects data from direct manipulation.
    True
  • Inheritance avoids repetitive coding.

    True
  • Method overloading allows a class to have multiple methods with the same name but different signatures.

    True
  • The state of an object is defined by its properties or attributes.

    True
  • The `new` keyword is used to create an object in OOP.

    True
  • To create an object, you use the `new` keyword along with the class name and call the constructor
  • Match the OOP concept with its description:
    Class ↔️ Blueprint for objects
    Object ↔️ Instance of a class
    Constructor ↔️ Method to initialize object state
  • What does encapsulation aim to achieve in OOP?
    Data hiding
  • Method overriding in polymorphism allows subclasses to customize inherited behavior.

    True
  • What are the two components of an object in OOP?
    State and behavior
  • If no constructor is defined, Java provides a default constructor.

    True
  • What are attributes within an object used for?
    Hold the object's data
  • The syntax for defining a method within a class starts with the access
  • Mutator methods (setters) are used to modify the values of an object's attributes.

    True
  • Methods operate on the object's data
  • Match the method type with its purpose:
    Accessor (Getter) ↔️ Retrieve attribute values
    Mutator (Setter) ↔️ Modify attribute values
  • What are methods within objects called?
    Behaviors or actions
  • Mutator methods are also known as setters
  • Steps involved in object-oriented programming (OOP):
    1️⃣ Organize code into objects
    2️⃣ Bundle data and methods
    3️⃣ Apply encapsulation
    4️⃣ Apply inheritance
    5️⃣ Apply polymorphism
  • Polymorphism enables objects of different classes to be treated as objects of a common superclass
  • What defines the properties or attributes of an object in OOP?
    State
  • What keyword is used to create an object from a class?
    new
  • What does a class define about an object?
    State and behavior
  • A constructor is a special method within a class that initializes the object's state
  • What are the parameters required for the parameterized constructor of the `Person` class?
    String name and int age
  • What are the three attributes defined in the `Person` class example?
    String name, int age, Address address
  • What are methods within objects called?
    Behaviors or actions
  • A class is a blueprint or template for creating objects.

    True
  • To create an object, you use the `new` keyword along with the class name and call the constructor
  • Inheritance allows new classes to inherit properties and methods from existing ones, promoting code reuse
  • In OOP, an object is a self-contained entity that bundles data and methods
  • Object creation involves using the `new` keyword and a constructor.

    True
  • Attributes define the state of an object by holding its data.

    True
  • Why is it recommended to define constructors explicitly in Java?
    Ensures proper initialization