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)
Fertigation system of irrigation is the
Which term in sericulture refers to the process of removing the sericin protein from silk fibers, resulting in smoother and more lustrous silk?
___________ is the process in which acids and bases react to form salts and water.
Which of the following part of stomach is called “True stomach”?
What percentage of the world's cotton cultivation area does India hold?
In which type of cooperative farming do members retain individual ownership of land?
Main function of bio-fertilizer is
Grass tetany is caused by:
National Income means
The Indian council of Agricultural Research (ICAR) set up an All India Soil Survey Committee in 1953 which divided the Indian soils into …….. major ...