Question: Java programming question 5. Consider the class below. public class Addition { private int sum = 0; public static void add (int x, int sum)
Java programming question



![main(String[] args) { int sum = 0; add (2, sum); add (3,](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2f658a6002_80866f2f65854673.jpg)


5. Consider the class below. public class Addition { private int sum = 0; public static void add (int x, int sum) { sum += x; } //end method add public static void main(String[] args) { int sum = 0; add (2, sum); add (3, sum) ; add (4, sum); System.out.println("The total is: " + sum); } //end main method } //end class Addition expected the program's output to say: The total is: 9 That is, the programmer wanted the add method to add values to the sum class variable. Fix the code so that it works properly by making edits such as changing names, crossing out code, adding code, etc
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
