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)
What is the primary objective of the Banking Ombudsman Scheme introduced by the RBI?
Institution of suits is provided under which section of CPC?
Arson means____________________
The Speaker of the Lok Sabha is:
Under the Bharatiya Nyaya Sanhita, 2023, which section defines "offence"?
For the enforcement of Fundamental Rights, the Supreme Court may issue a/an
Which Part of the Constitution of India consists of Emergency provisions?
As per Reg 7J of SEBI (Prohibition of Insider Trading) Regulations, 2015, what is the effect of a term in an agreement or Code of Conduct that precl...
Doctrine of Res gestae is an exception to?
Which one of the following is not a public documents________.