Ask Question

What is the output of the program shown below?

public class SomeClass

{

private int x, y;

public SomeClass (int xValue, int yValue)

{

x = xValue;

y = yValue;

}

public void m1 ()

{

x = 30;

System. out. print ((y + 1) + " ");

}

public void m2 ()

{

m1 ();

System. out. print (x + " ");

}

}

public class SomeTester

{

public static void main (String[] args)

{

int x = 10;

int y = 20;

SomeClass z = new SomeClass (x, y);

z. m2 ();

z. m1 ();

}

}

21 10 21

21 30 21

11 30 11

1 10 11

11 30 21

+4
Answers (1)
  1. 2 April, 03:38
    0
    21 10 21

    Explanation:

    The called functions are m2 () first which has the following implementation it called m1 () which changes the value of x to 30 and print out y + 1 = 21 note x = 30 within m1 () after execution of m1 () x = 10 then called m1 x = 30 and print out y + 1 = 21 therefore answer is

    21 10 21
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the output of the program shown below? public class SomeClass { private int x, y; public SomeClass (int xValue, int yValue) { x = ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers