Question
What will the following Java code snippet output when
executed, which uses a simple constructor and method overloading ? class Calculator { Â Â Â int add ( int a, int b) { Â Â Â Â Â Â Â return a + b; Â Â Â } Â Â Â double add ( double a, double b) { Â Â Â Â Â Â Â return a + b; Â Â Â } Â Â Â public static void main (String[] args) { Â Â Â Â Â Â Â Calculator calc = new Calculator (); Â Â Â Â Â Â Â System.out.println(calc.add( 5 , 10 ));Â Â Â Â Â // Line 1 Â Â Â Â Â Â Â System.out.println(calc.add( 5.5 , 10.5 ));Â // Line 2 Â Â Â }}Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂSolution
In this example, the Calculator class defines two add() methods with the same name but different parameter types: one for integers and another for doubles. This is an example of method overloading . Let's examine why A is the correct answer and the other options are incorrect:
- Explanation of Correct Option (A):
- The method add(int a, int b) accepts integers and returns an integer result. When calc.add(5, 10)
Which banks are NOT covered under these Reserve Bank of India (Interest Rate on Advances) Directions, 2016?
Which of the following statements about stock markets is/are correct?
1)Â Â Â Stock markets provide a platform for companies to raise funds t...
.......... represents that quantity of material which is normally ordered when a particular material reaches the ordering level.Â
The price specified on an option that the holder can buy or sell the underlying asset is called the:
Which of the following financial reports are considered to be of the lowest quality? Financial reports that reflect:
Loans up to how much amount are allowed for repairing damaged dwelling units in metropolitan centres?
What is the authorized share capital that the National Payments Corporation of India (NPCI) has fixed?
What is the key purpose of the Tariff Rate Quota (TRQ) mechanism as outlined in the RBI circular on the import of gold by TRQ holders?
Â
Which of the following is a disadvantage of the payback period method in capital budgeting?
Imputed cost is _______