Question:

In a calculator which Java feature allows multiple methods named calculate() for the different operations?

Show Hint

When the same method name is used with different parameters in Java, it is called \textbf{method overloading}, which is an example of \textbf{polymorphism}.
  • abstraction
  • inheritance
  • encapsulation
  • polymorphism
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understand what the question is asking.
The question asks which Java feature allows us to use the same method name, such as calculate(), for performing different operations. For example, in a calculator program, we may want one calculate() method for addition, another for subtraction, another for multiplication, and so on.
Step 2: Recall the related Java concept.
In Java, when the same method name is used in different forms, usually with different parameter lists, this is called method overloading. Method overloading is one of the most common examples of polymorphism, specifically compile-time polymorphism.
So, if multiple methods have the same name calculate() but behave differently depending on the arguments passed, the feature involved is polymorphism.
Step 3: Compare the given options.
  • (A) abstraction: Incorrect. Abstraction hides implementation details and shows only essential features.
  • (B) inheritance: Incorrect. Inheritance allows one class to acquire the properties and methods of another class.
  • (C) encapsulation: Incorrect. Encapsulation binds data and methods together and restricts direct access to data.
  • (D) polymorphism: Correct. Polymorphism allows the same method name to perform different tasks in different situations.
Step 4: Conclusion.
Therefore, the Java feature that allows multiple methods named calculate() for different operations is polymorphism.
Final Answer:polymorphism.
Was this answer helpful?
0
0

Top Questions on Object-Oriented Programming

View More Questions