Search Tutorials


Java Polymorphism MCQ - Multiple Choice Questions And Answers | JavaInUse

Java Polymorphism MCQ - Multiple Choice Questions And Answers

Q. What is polymorphism in Java?

A. The ability of a method to do different things based on the object it is acting upon
B. The process of creating multiple instances of a class
C. The ability to inherit properties from multiple classes
D. The process of converting primitive data types into objects

Q. Which type of polymorphism is achieved through method overriding in Java?

A. Compile-time polymorphism
B. Runtime polymorphism
C. Static polymorphism
D. Dynamic polymorphism

Q. Can objects of different classes within the same inheritance hierarchy be used interchangeably in Java?

A. Yes, always
B. No, never
C. Only if they have a common superclass
D. Only if they have a common subclass

Q. What is method overloading in Java?

A. The process of creating multiple methods with the same name but different parameters
B. The process of creating multiple instances of a class
C. The ability to inherit properties from multiple classes
D. The process of converting primitive data types into objects

Q. Which keyword is used to achieve method overriding in Java?

A. extend
B. super
C. this
D. @Override

Q. What is the purpose of the super keyword in Java?

A. To call methods in the superclass
B. To restrict access to certain methods
C. To define a new class
D. To create an instance of a class

Q. Can a subclass reference be used to access superclass-specific members in Java?

A. Yes, always
B. No, never
C. Only if the members are static
D. Only if the subclass overrides the members

Q. Which type of polymorphism is achieved through method overloading in Java?

A. Compile-time polymorphism
B. Runtime polymorphism
C. Static polymorphism
D. Dynamic polymorphism

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. What is method hiding in Java?

A. The process of making a method private in a subclass
B. The process of changing the return type of a method in a subclass
C. The process of overriding a static method in a superclass
D. The process of overriding a non-static method in a superclass

Q. Can a subclass override a private method of its superclass in Java?

A. Yes, always
B. No, never
C. Only if the superclass is abstract
D. Only if the subclasses are in the same package as the superclass

Q. Which keyword is used to prevent a class from being subclassed in Java?

A. final
B. abstract
C. static
D. private





Q. In Java, can a method be overridden by another method in the same class?

A. Yes, always
B. No, never
C. Only if the methods have different return types
D. Only if the methods have different parameter lists

Q. What is the difference between method overloading and method overriding in Java?

A. Method overloading is when a subclass defines a method with the same name as a method in its superclass, while method overriding is when a subclass provides a specific implementation of a method that is already provided by its parent class
B. Method overloading is when a method can do different things depending on the object it is acting upon, while method overriding is when a method implements a generic functionality for objects of different types
C. Method overloading is for static methods, while method overriding is for instance methods
D. There is no difference between method overloading and method overriding

Q. In Java, can a subclass override a static method in its superclass?

A. Yes, always
B. No, never
C. Only if the superclass is abstract
D. Only if the subclass also declares the method as static

Q. What is dynamic polymorphism in Java?

A. The ability to have multiple methods with the same name in a class
B. The process of converting an object of one class to an object of another class
C. The process of creating instances of a subclass
D. The ability to override a method in a subclass

Q. In Java, can a subclass add new methods not present in its superclass?

A. Yes, always
B. No, never
C. Only if the superclass is abstract
D. Only if the superclass is final

Q. What is method signature in Java?

A. The return type of a method only
B. The name and parameter list of a method
C. The name and access specifier of a method
D. The name and return type of a method

Q. When is method overriding used in Java?

A. When a subclass method wants to provide a specific implementation of a method already provided by its parent class
B. When a subclass method wants to hide a method in the superclass
C. When a subclass method needs to call a method in the superclass
D. When a subclass method wants to enhance the method signature of the superclass

Q. Can abstract classes have constructors

A. Yes, but only default constructors
B. Yes, but only parameterized constructors
C. No, abstract classes cannot have constructors
D. No, abstract classes can only have static constructors

Q. What is polymorphism in Java?

A. Polymorphism is the ability of a variable, method, or object to take on multiple forms.
B. Polymorphism is the ability to define different implementations of a method in the same class.
C. Polymorphism is the ability of a class to extend another class and inherit its properties and methods.
D. Polymorphism is the process of combining multiple methods into a single method name.

Q. Which of the following best describes method overloading in Java?

A. Method overloading is creating multiple methods with the same name in a single class, but with different parameters.
B. Method overloading is creating a method in a subclass that has the same name and signature as a method in the superclass.
C. Method overloading is a way to define methods in an interface that have different behavior.
D. Method overloading is the ability of a method to be defined in multiple classes that inherit from each other.

Q. Which of the following code snippets demonstrates method overriding in Java?

A.
    public class Parent {
        public void display() {
            System.out.println("Parent Display");
        }
    }
    public class Child extends Parent {
        public void display() {
            System.out.println("Child Display");
        }
    }
    
B.
    public class Parent {
        public void print() {
            System.out.println("Parent Print");
        }
    }
    public class Child extends Parent {
        public void print() {
            System.out.println("Child Print");
        }
    }
    
C.
    public class Parent {
        public void show() {
            System.out.println("Parent Show");
        }
    }
    public class Child extends Parent {
        public void show() {
            System.out.println("Child Show");
        }
    }
    
D.
    public class Parent {
        public void output() {
            System.out.println("Parent Output");
        }
    }
    public class Child extends Parent {
        public void output() {
            System.out.println("Child Output");
        }
    }
    

Q. What is runtime polymorphism in Java?

A. Runtime polymorphism is the ability of Java to resolve method calls at compile time.
B. Runtime polymorphism is the ability of an object to take on different forms during program execution.
C. Runtime polymorphism is the process of implementing multiple interfaces in a single class.
D. Runtime polymorphism is the process of creating multiple instances of the same class.

Q. Which keyword is used to implement method overriding in Java?

A. override
B. inherit
C. super
D. @Override