Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What will be the output of the program? class PassA { public static void main(St

ID: 3542209 • Letter: W

Question

    
What will be the output of the program?

class PassA
{
    public static void main(String [] args)
    {
        PassA p = new PassA();
        p.start();
    }

    void start()
    {
        long [] a1 = {3,4,5};
        long [] a2 = fix(a1);
        System.out.print(a1[0] + a1[1] + a1[2] + " ");
        System.out.println(a2[0] + a2[1] + a2[2]);
    }

    long [] fix(long [] a3)
    {
        a3[1] = 7;
        return a3;
    }
}
A.    12 15               B.    15 15
C.    3 4 5 3 7 5      D.    3 7 5 3 7 5

Explanation / Answer

C) 3 4 5 3 7 5


I will explain why this comes

when you call fix function a2 is modified as [3 7 5[


a1 remains [3 4 5]

a2 is [3 7 5]


now since the print statement has a +" " , this do string addition rather than integer addition

that is 3 + 4 + 5 will be equal to 345 and not 15



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote