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)
Aflatoxin, a mycotoxin produced by Aspergillus, is associated with ____ crop.Â
Cyclamate is how many times sweeter than sucrose
Essentiality of zinc in plant was discovered in 1926 by
The seedling of which plants are thorny during juvenile phase
A. Apple
B. Pear
C. Citrus
D. Guava
E. Mango
Cho...
For the analysis of variance of data from plot sampling in a CRD with 't' treatments, ‘r’ replications and 's' sampling units per plot, sampling err...
Weight of Urea super granules is
APEDA ( Agricultural and Processed Food Products Export Development Authority) established under which of the following Ministry?
Caculate the amount of urea fr 4000 m2 area if nitrogen appication rate is 120 kg/ha
Calculate the seed rate (kg/ha) of wheat, if crop is sown at spacing of 18 cm×3 cm and rest weight of seed is 44 gram
Which of the following crop is highly tolerant to alkalinity?