Polymorphism Interview Questions

    Question 1JAVA OOPS - Compile-time Polymorphism

    Which of the following demonstrates compile-time polymorphism in Java?

    class Demo { void show() { System.out.println("No-arg"); } void show(int x) { System.out.println(x); } }

    Question 2JAVA OOPS - Method Overloading Example

    What will be printed?

    class Demo { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } } public class Main { public static void main(String[] args) { Demo d = new Demo(); System.out.println(d.add(5, 5)); System.out.println(d.add(5.0, 5.0)); } }

    Question 3JAVA OOPS - Runtime Polymorphism

    What will be printed?

    class A { void show() { System.out.println("A"); } } class B extends A { void show() { System.out.println("B"); } } public class Main { public static void main(String[] args) { A obj = new B(); obj.show(); } }

    Question 4JAVA OOPS - Polymorphism with Parameters

    Which of the following is true about polymorphism in Java?

    Question 5JAVA OOPS - `super` in Runtime Polymorphism

    What will be printed?

    class A { void show() { System.out.println("Parent"); } } class B extends A { void show() { super.show(); System.out.println("Child"); } } public class Main { public static void main(String[] args) { B obj = new B(); obj.show(); } }

    Question 6JAVA OOPS - Polymorphism with Return Type

    Which is true about overriding and return types?

    Question 7JAVA OOPS - Static Method and Polymorphism

    Which statement is correct?

    Question 8JAVA OOPS - Constructor and Polymorphism

    Which statement is true?

    Question 9JAVA OOPS - Polymorphism with Abstract Class

    Which is true?

    Question 10JAVA OOPS - Interface and Polymorphism

    Which is correct regarding interface polymorphism?