Last Updated: January 3, 2026
31 quizzes
Use a single polymorphic call to display details of the current Shape object.
shape.();Click an option to fill the blank:
Invoke the correct overloaded method to calculate the total price using a double value.
double total = calculator.(19.99);Click an option to fill the blank:
Create a polymorphic reference so that a ReportGenerator variable can refer to a PdfReportGenerator instance.
ReportGenerator generator = PdfReportGenerator();Click an option to fill the blank:
In Java polymorphism, what does it mean to treat an object as an instance of its parent class?
Which statement best describes compile-time polymorphism in Java?
What is required for runtime polymorphism using method overriding?
Dynamic method dispatch decides which method implementation to call based on which factor?
Which of the following is an example of covariant return types?
Which scenario best benefits from runtime polymorphism in a real application?
In method overloading, which parts of the method definition must be different?
Which keyword helps prevent further overriding of a method, affecting polymorphism?
How does dynamic method dispatch interact with collections of a base type, like List<Shape>?
Which is TRUE about static methods and polymorphism?
Which code snippet correctly demonstrates a covariant return type in a subclass?
Order the steps to use runtime polymorphism for processing different Payment types (e.g., CardPayment, WalletPayment).
Drag and drop to reorder, or use the arrows.
Order the steps to implement and use covariant return types in a repository pattern.
Drag and drop to reorder, or use the arrows.
What is the output of this code involving method overloading?
1class Printer {
2 void print(String s) { System.out.println("String: " + s); }
3 void print(Object o) { System.out.println("Object: " + o); }
4}
5public class Main {
6 public static void main(String[] args) {
7 Printer p = new Printer();
8 Object ref = "Hello";
9 p.print(ref);
10 }
11}What is the output of this runtime polymorphism example?
1class Notification {
2 String getType() { return "Generic"; }
3}
4class EmailNotification extends Notification {
5 String getType() { return "Email"; }
6}
7public class Main {
8 public static void main(String[] args) {
9 Notification n = new EmailNotification();
10 System.out.println(n.getType());
11 }
12}What will this code print when using covariant return types?
1class Report {
2 Report create() { return new Report(); }
3}
4class PdfReport extends Report {
5 @Override
6 PdfReport create() { return new PdfReport(); }
7}
8public class Main {
9 public static void main(String[] args) {
10 Report r = new PdfReport();
11 Report result = r.create();
12 System.out.println(result.getClass().getSimpleName());
13 }
14}What is the output of this code using dynamic dispatch on an array?
1class Shape {
2 String draw() { return "shape"; }
3}
4class Circle extends Shape {
5 String draw() { return "circle"; }
6}
7public class Main {
8 public static void main(String[] args) {
9 Shape[] shapes = { new Shape(), new Circle() };
10 System.out.println(shapes[1].draw());
11 }
12}What does this code print, illustrating overloaded and overridden methods?
1class Logger {
2 void log(Object o) { System.out.println("Object: " + o); }
3}
4class FileLogger extends Logger {
5 @Override
6 void log(Object o) { System.out.println("File: " + o); }
7 void log(String s, int level) { System.out.println("String: " + s + "@" + level); }
8}
9public class Main {
10 public static void main(String[] args) {
11 Logger logger = new FileLogger();
12 logger.log("event");
13 }
14}This code tries to demonstrate runtime polymorphism with dynamic method dispatch for payments. Identify the bug that prevents overriding.
Click on the line(s) that contain the bug.
class Payment { static void process() { System.out.println("Generic payment"); }}class CardPayment extends Payment { static void process() { System.out.println("Card payment"); }}public class Main { public static void main(String[] args) { Payment p = new CardPayment(); p.process(); }}This code attempts to use a covariant return type in a subclass. Find the bug.
Click on the line(s) that contain the bug.
class Document { Document cloneDoc() { return new Document(); }}class PdfDocument extends Document { @Override String cloneDoc() { return "pdf"; }} Match each polymorphism-related term to its correct description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each concept to its closest real-world example of polymorphic use.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to demonstrate dynamic method dispatch for sending messages.
class MessageSender { String send() { return "generic"; }}class SmsSender extends MessageSender { @Override String send() { return "sms"; }}public class Main { public static void main(String[] args) { sender = new SmsSender(); System.out.println(sender.()); }}Click an option to fill blank 1:
Fill in the blanks to correctly overload a method that calculates discounts.
class DiscountCalculator { int apply(int amount) { return amount - 10; } int apply( amount, rate) { return amount - (int)(amount * rate); }}Click an option to fill blank 1:
Complete the code to show covariant return types in a configuration loader.
class Config { Config load() { return new Config(); }}class AppConfig extends Config { @Override load() { return new AppConfig(); }}public class Main { public static void main(String[] args) { Config c = new AppConfig().load(); System.out.println(c.getClass().()); }}Click an option to fill blank 1:
Fill in the blanks to use an overridden draw() method through a polymorphic reference.
abstract class Shape { abstract void draw();}class Rectangle extends Shape { @Override void draw() { System.out.println("rectangle"); }}public class Main { public static void main(String[] args) { Shape shape = new (); shape.(); }}Click an option to fill blank 1:
Click the line where dynamic method dispatch decides which implementation of speak() to execute.
Click on the line to select.
class Animal { void speak() { System.out.println("Animal"); }}class Dog extends Animal { @Override void speak() { System.out.println("Dog"); }}public class Main { public static void main(String[] args) { Animal a = new Dog(); a.speak(); }}Click the line that shows a covariant return type overriding a superclass method.
Click on the line to select.
class Connection { Connection open() { return new Connection(); }}class SecureConnection extends Connection { @Override SecureConnection open() { return new SecureConnection(); }}