object oriented programming

    Cards (30)

    • What is a class in programming?
      A class forms a blueprint to instantiate/create an object.
    • What is a subclass?
      A subclass is below a superclass in the class hierarchy.
    • What does a subclass inherit from a superclass?
      A subclass inherits all of the attributes and methods of the superclass.
    • Can a subclass have its own attributes and methods?
      Yes
    • What is the relationship between a subclass and a superclass?
      • A subclass is a specialized version of a superclass.
      • It inherits all features of the superclass.
      • It can have additional features, making it more specific.
    • What are the characteristics of multiple subclasses in inheritance?
      • Each subclass can inherit from the same superclass.
      • Examples include `Dog`, `Cat`, and `Bird` inheriting from `Animal`.
      • They can share common behavior while defining their own specific behaviors.
    • What is polymorphism in programming?
      Polymorphism allows treating different subclasses as instances of the superclass.
    • How can polymorphism be demonstrated with a list of objects?
      You can create a list of `Animal` objects that includes `Dog`, `Cat`, and `Bird` and call the `speak` method on each.
    • What are the benefits of having a superclass with multiple subclasses?
      • A superclass can have multiple subclasses with specific attributes and methods.
      • This allows for flexible and organized code structure.
      • Enables reuse of common functionality while allowing specialized behavior in subclasses.
    • What is a common interface in polymorphism?
      A common interface is a method defined in the superclass that subclasses can override.
    • What does it mean for objects to be interchangeable in polymorphism?
      Interchangeable objects can be used in collections as long as they share the same superclass.
    • What are methods in the context of classes?
      Methods are subroutines (functions) that allow the object to perform actions.
    • What are attributes in the context of classes?
      Attributes are variables that describe the object.
    • How are classes created in Java?
      Classes are created using the `class` keyword.
    • What does the `public` keyword signify in Java classes?
      The `public` keyword means anyone can access the class from any part of the code.
    • How are class methods accessed in Java?
      Class methods are accessed using dot notation.
    • What keyword is used to create an object in Java?
      The keyword used to create an object is `new`.
    • What is encapsulation in programming?
      • Encapsulation means keeping data safe from direct modification.
      • It is often known as information hiding.
    • Can an instance of a class alter the data of another instance of the same class?
      No, an instance of a class cannot alter the data of another instance of the same class.
    • Is the statement "An instance of a class can alter the data of another instance of the same class" true or false?
      False
    • What is polymorphism in object-oriented programming?
      Polymorphism is when a subclass alters its inherited methods by overloading or overriding.
    • What are the two ways a subclass can alter its inherited methods?
      • Overloading
      • Overriding
    • What does the `Shape` superclass define?
      The `Shape` superclass defines a generic `area` method.
    • How do the `Circle` and `Triangle` subclasses implement the `area` method?
      They define their own versions of `area` with different parameter lists.
    • What is the parameter list for the `Circle.area` method?
      The `Circle.area` method takes one argument, `radius`.
    • What is the parameter list for the `Triangle.area` method?
      The `Triangle.area` method takes two arguments, `base` and `height`.
    • What is method overloading?
      • Methods with the same name but different parameter lists
      • Allows similar operations for different types of shapes
    • Why is overloading beneficial in programming?
      Overloading makes code more flexible and easier to maintain.
    • What is method overriding?
      • Subclass refines or customizes behavior defined by the superclass
      • Useful for specific needs of the subclass
    • When is overriding particularly useful?
      When a superclass defines a general behavior that needs refinement in a subclass.