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 film emerged victorious at the ALT Environment Film Festival?Â
India will have combined military exercise "Ajeya Warrior – 2017" with which of the following country?
Which company has launched a Multi-Channel Fulfillment (MCF) through which brands, manufacturers, and retailers from across industries can enhance their...
How much did Deutsche Bank’s recent (Nov 2024) capital infusion aim to benefit its India operations?
Which village in Manipur is Hathei chilli, celebrated at the Sirarakhong Hathei Chilli Festival, native to?
What is the maximum time period given to the states to repay the Ways and Means Advances extended to them by the RBI?
Swiss brokerage UBS has revised upwards its India growth forecast by 70 bps to________Â for the current fiscal.
Consider the following statements :
I . An Indian - Origin Sikh Volunteer Amar Singh was honoured with Australian of the Year Award .
II ....
Who has been appointed as the next President of the African Development Bank (AfDB)?
Which of the following is being developed as the first elevated urban expressway in India, will be operational in 2023?