Question:

In the following method prototype to accept a character, an integer and return YES or NO, fill in the blank to complete the method prototype. \[ \texttt{public ________ someMethod(char ch, int n)} \]

Show Hint

Whenever a method is expected to return a yes/no type logical result, the most suitable return type in Java is \texttt{boolean}.
  • boolean
  • String
  • int
  • double
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Understand the meaning of the method prototype.
A method prototype tells us what type of value the method will return after execution. In the given prototype, the method accepts two parameters: \[ \texttt{char ch} \] and \[ \texttt{int n} \] Now we have to identify the correct return type for a method that gives an answer in the form of \texttt{YES} or \texttt{NO}.
Step 2: Relate YES/NO to programming data types.
In programming, a YES/NO type result usually represents a logical decision. A logical decision has only two possible outcomes: \[ \texttt{true} \text{ or } \texttt{false} \] In Java, the data type used for such two-way logical outcomes is: \[ \texttt{boolean} \] So, if the method is supposed to check a condition and indicate whether it is satisfied or not, the most suitable return type is \texttt{boolean}.
Step 3: Compare with the given options.
  • (A) boolean: Correct. It is used when the method returns a logical result such as true or false, which corresponds to YES or NO.
  • (B) String: Incorrect. A String would return text like \texttt{"YES"} or \texttt{"NO"}, but for logical decisions the standard return type is \texttt{boolean}.
  • (C) int: Incorrect. An integer returns numeric values, not logical results.
  • (D) double: Incorrect. A double returns decimal values, which is not suitable here.
Step 4: Complete the method prototype.
Thus, the correct method prototype will be: \[ \texttt{public boolean someMethod(char ch, int n)} \] Hence, the blank must be filled with \texttt{boolean}.
Final Answer:boolean.
Was this answer helpful?
0
0

Top Questions on Object-Oriented Programming

View More Questions