Inheritance and Polymorphism MCQS [Object Oriented Programming with Java — 150704]

Computer Bits Daily
5 min readApr 5, 2023

Inheritance and Polymorphism mcq AND ANSWERS : Inheritance in java, Super and sub class, Overriding, Object class, Polymorphism, Dynamic binding, Generic programming, Casting objects, Instance of operator, Abstract class, Interface in java, Package in java, UTIL package.

Subject Name: Object Oriented Programming with Java Subject Code: 150704

https://play.google.com/store/apps/details?id=com.javamcq.programs.interviewcomputerbitsdaily&hl=en&gl=US

Which keyword is used to create a subclass in Java?
Answer: The keyword used to create a subclass in Java is “extends”.
Explanation: Inheritance allows creating a new class that is a modified version of an existing class. The new class is called a subclass, and the existing class is called the superclass. In Java, the keyword “extends” is used to create a subclass that inherits the properties and methods of the superclass.

What is the difference between the “super” keyword and “this” keyword in Java?
Answer: The “super” keyword is used to refer to the superclass, whereas the “this” keyword is used to refer to the current object.
Explanation: The “super” keyword is used to call a constructor or method of the superclass, or to access a property of the superclass that has been hidden by a property of the subclass. The “this” keyword is used to refer to the current object, and is often used to avoid naming conflicts between local variables and instance variables.

What is method overriding in Java?
Answer: Method overriding in Java is the process of providing a new implementation for a method that is already defined in the superclass.
Explanation: When a method is overridden, the new implementation is used instead of the old implementation. The method in the subclass must have the same name, return type, and parameter list as the method in the superclass. The “@Override” annotation is often used to indicate that a method is intended to override a method in the superclass.

What is the Object class in Java?
Answer: The Object class in Java is the root class of all Java classes.
Explanation: The Object class is the parent class of all Java classes. It provides a number of methods that are inherited by all Java classes, such as toString(), equals(), and hashCode(). These methods can be overridden in subclasses to provide custom implementations.

What is polymorphism in Java?
Answer: Polymorphism in Java is the ability of an object to take on multiple forms.
Explanation: Polymorphism allows objects of different classes to be treated as if they were objects of the same class. This is often achieved through inheritance and method overriding. Polymorphism can make code more flexible and reusable.

What is dynamic binding in Java?
Answer: Dynamic binding in Java is the process of determining which implementation of a method to call at runtime.
Explanation: Dynamic binding allows a program to determine which implementation of a method to call based on the actual type of the object at runtime, rather than the declared type of the variable. This can be useful for achieving polymorphism.

What is casting in Java?
Answer: Casting in Java is the process of converting one data type to another data type.
Explanation: Casting is often used when an object is returned as a superclass type, but needs to be treated as a subclass type. Casting can be used to convert the superclass reference to a subclass reference, so that the subclass-specific methods and properties can be accessed.

What is the instanceof operator in Java?
Answer: The instanceof operator in Java is used to check whether an object is an instance of a particular class or interface.
Explanation: The instanceof operator returns true if the object is an instance of the specified class or interface, or if it is an instance of a subclass of the specified class or interface.

What is an abstract class in Java?
Answer: An abstract class in Java is a class that cannot be instantiated and is meant to be extended by subclasses.
Explanation: An abstract class is a class that contains one or more abstract methods, which are methods without a body. Subclasses of an abstract class must provide implementations for all abstract methods. Abstract classes can also have non-abstract methods and properties.

What is the purpose of inheritance in Java?

a) To allow classes to share common properties and methods

b) To allow classes to have unique properties and methods

c) To prevent classes from sharing common properties and methods

d) None of the above
Answer: a) To allow classes to share common properties and methods Inheritance allows a class to inherit properties and methods from a superclass. This allows for code reuse and can make it easier to maintain and update code.

Which keyword is used to call a superclass’s constructor?

a) super b) this c) extends d) implements
Answer: a) super The super keyword is used to call a superclass’s constructor from within a subclass’s constructor.

What is method overriding in Java?

a) Defining a method in a subclass with the same signature as a method in the superclass

b) Defining a method in a subclass with a different signature than a method in the superclass

c) Defining a method in an interface with the same signature as a method in an implementing class

d) None of the above
Answer: a) Defining a method in a subclass with the same signature as a method in the superclass Method overriding allows a subclass to provide its own implementation of a method that is already defined in its superclass.

What is the purpose of the Object class in Java?

a) To provide common methods for all classes

b) To provide unique methods for specific classes

c) To prevent classes from sharing common methods

d) None of the above
Answer: a) To provide common methods for all classes The Object class is the root of the class hierarchy in Java. All classes inherit from Object, either directly or indirectly, and therefore have access to its methods.

https://play.google.com/store/apps/details?id=com.javamcq.programs.interviewcomputerbitsdaily&hl=en&gl=US

What is polymorphism in Java?

a) The ability of an object to take on many forms b) The ability of an object to take on only one form c) The ability of an object to change its form at runtime d) None of the above
Answer: a) The ability of an object to take on many forms Polymorphism allows objects to be treated as instances of their own class or as instances of any superclass or interface they implement.

https://play.google.com/store/apps/details?id=com.javamcq.programs.interviewcomputerbitsdaily&hl=en&gl=US

What is dynamic binding in Java?

a) The process of determining which method to call at compile-time b) The process of determining which method to call at runtime c) The process of determining which variable to use at compile-time d) None of the above
Answer: b) The process of determining which method to call at runtime Dynamic binding allows the JVM to determine which method implementation to call based on the actual type of the object at runtime.

What is generic programming in Java? a) Writing code that can work with multiple data types b) Writing code that can only work with one data type c) Writing code that can change data types at runtime d) None of the above
Answer: a) Writing code that can work with multiple data types Generic programming allows you to write code that can work with multiple data types by using type parameters.

Which operator is used to determine if an object is an instance of a particular class or interface? a) instanceof b) typeof c) extendsof d) implements
Answer: a) instanceof The instanceof operator can be used to determine if an object is an instance of a particular class or interface.

https://play.google.com/store/apps/details?id=com.javamcq.programs.interviewcomputerbitsdaily&hl=en&gl=US

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Computer Bits Daily
Computer Bits Daily

Written by Computer Bits Daily

Learning Computer skills and Computer technology by learning and sharing

No responses yet

Write a response