97.1k views
2 votes
What will be returned from the following method? public static double myMethod() { double a = 1.5 + 9.5; return a; }

1 Answer

0 votes

Final answer:

The Java method 'public static double myMethod()' will return 11.0 after adding 1.5 and 9.5. This method demonstrates basic arithmetic operations and variable assignment in Java.

Step-by-step explanation:

The student has asked about what value would be returned by a Java method. The method in question is public static double myMethod() which performs a simple arithmetic operation. The operation consists of adding two double values: 1.5 and 9.5. When this method is called, it first calculates the sum of these two numbers and then returns the result.

To break it down, the code performs the following steps:

  • It declares a variable 'a' of type double.
  • It assigns the sum of 1.5 and 9.5 to the variable 'a'.
  • It then returns the value of 'a'.

After calculating the sum (1.5 + 9.5), the method will return 11.0 as 'a' will have this value assigned.

User Chris Gillatt
by
7.7k points