Which of the following is an example of dynamic dispatch? A: Assume you have an interface Car. There are three classes that implement the Car interface: Accord, Civic, Charger. Each of these classes has their own drive() method. There is an object myCar of type Car. When you invoke the drive() method, by calling myCar.drive() the correct implementation of drive() is chosen at runtime based upon the concrete class of myCar. B: Assume you have a variable myVariable. You have a for loop. The first time through the loop you set myVariable to an int, the next time you set it as a double, the next time a String, and finally an int. Each iteration of the loop myVariable has the correct type. C: Assume you have a class call Computation. Your computation class has a static method called add(). This method has three different versions: add(int x, int y) add(float x, float y) add(double x, double y) When you run Computation.add(x,y) the correct version of the method is chosen at compile time based upon the types of the input given to the function. D: Some classes has static methods and static fields, that can be accessed without creating an instance of an object. Others have dynamic methods that need an object to be created and instantiated, then those methods can be accessed dynamically
Which of the following is an example of dynamic dispatch?
A: Assume you have an interface Car. There are three classes that implement the Car interface: Accord, Civic, Charger. Each of these classes has their own drive() method. There is an object myCar of type Car. When you invoke the drive() method, by calling myCar.drive() the correct implementation of drive() is chosen at runtime based upon the concrete class of myCar.
B: Assume you have a variable myVariable. You have a for loop. The first time through the loop you set myVariable to an int, the next time you set it as a double, the next time a String, and finally an int. Each iteration of the loop myVariable has the correct type.
C: Assume you have a class call Computation. Your computation class has a static method called add(). This method has three different versions:
add(int x, int y)
add(float x, float y)
add(double x, double y)
When you run Computation.add(x,y) the correct version of the method is chosen at compile time based upon the types of the input given to the function.
D: Some classes has static methods and static fields, that can be accessed without creating an instance of an object. Others have dynamic methods that need an object to be created and instantiated, then those methods can be accessed dynamically.
Step by step
Solved in 2 steps