9.3 Polymorphism

    Cards (89)

    • Method overriding is an example of dynamic polymorphism
      True
    • Dynamic polymorphism is determined at runtime
      True
    • Method overriding is an example of dynamic polymorphism
      True
    • At what time is dynamic polymorphism resolved?
      Runtime
    • What determines which method to call in static polymorphism?
      Argument types
    • Static polymorphism is also known as method overloading
    • In Java, polymorphism allows an object of a parent class to be treated as an object of one of its child classes
    • In dynamic polymorphism, the method to execute is determined at runtime
    • Dynamic polymorphism allows subclasses to customize inherited methods.

      True
    • The `makeSound` method is overridden in both the `Dog` and `Cat` classes to provide specific sounds.

      True
    • Dynamic polymorphism is determined at runtime.

      True
    • Classes implementing interfaces must provide implementations for all methods.

      True
    • In the example with the `Vehicle` class, what keyword is used to declare the `start` method as abstract?
      abstract
    • Static polymorphism is also known as method overloading.

      True
    • When does method overloading occur in Java?
      Multiple methods with same name
    • How does polymorphism enhance code reusability in Java?
      Single method works with multiple classes
    • In the `Calculator` class example, what input types can the `add` method handle?
      Integers or doubles
    • Static polymorphism in Java is also known as method overloading
    • Dynamic polymorphism occurs when a subclass redefines a method from its parent class with the same name and parameters
    • In the example with the `Animal` class, the `makeSound` method is overridden in the `Dog` class to print Woof
    • In dynamic polymorphism, the binding of the method call occurs at runtime
    • In dynamic polymorphism, a subclass redefines a method from its parent class with the same name and parameters
    • What is the output of the `Dog` class's `makeSound` method?
      Woof!
    • Subclasses of an abstract class must override abstract methods.

      True
    • Classes implementing an interface must provide implementations for all its methods.

      True
    • Subclasses of an abstract class must override abstract methods.
      True
    • Method resolution in runtime polymorphism occurs at compile-time.
      False
    • Using polymorphism can lead to runtime errors if object types are incompatible.

      True
    • Steps to implement a method overloading exercise
      1️⃣ Create a class with a method that handles integers
      2️⃣ Create another method in the same class that handles doubles
      3️⃣ Call both methods with appropriate arguments
    • Polymorphism allows an object of a parent class to be treated as an object of one of its child classes
    • Static polymorphism is resolved at compile time.
    • Static polymorphism is used to provide multiple ways to perform the same action with different input types
    • The runtime determines which method to execute based on the actual type of the object
    • Polymorphism enhances code reusability by allowing a single method to work with objects of different classes
    • By leveraging polymorphism, developers can write more reusable and flexible code
    • Match the type of polymorphism with its key concept:
      Static Polymorphism ↔️ Method Overloading
      Dynamic Polymorphism ↔️ Method Overriding
    • Dynamic polymorphism occurs when a subclass redefines a method with the same name and parameter list as its parent class.

      True
    • Method overloading in Java is an example of static polymorphism
    • When the `makeSound` method is called on a `Cat` object, the output is Meow!
    • Static polymorphism involves method overloading