Knowee
Questions
Features
Study Tools

What will be the output of the following program?class test {int a;int b;test(int i, int j) {a = i;b = j;}void meth(test o) {o.a *= 2;o.b /= 2;}          }   class Output{public static void main(String args[]){test obj = new test(10 , 20);obj.meth(obj);System.out.println(obj.a + " " + obj.b);        }}Select one:40 2010 2020 1020 40

Question

What will be the output of the following program?class test {int a;int b;test(int i, int j) {a = i;b = j;}void meth(test o) {o.a *= 2;o.b /= 2;}          }   class Output{public static void main(String args[]){test obj = new test(10 , 20);obj.meth(obj);System.out.println(obj.a + " " + obj.b);        }}Select one:40 2010 2020 1020 40

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "20 10".

Here's the step by step explanation:

  1. An object of class test is created with a as 10 and b as 20.
  2. The meth method is called with the object itself as the argument.
  3. Inside the meth method, a is multiplied by 2 and b is divided by 2. So, a becomes 20 and b becomes 10.
  4. Finally, the values of a and b are printed which are 20 and 10 respectively.

This problem has been solved

Similar Questions

What will be the output of the following program?class string_class {public static void main(String args[]){String obj = "hello";String obj1 = "world";   String obj2 = obj;obj2 = " world";System.out.println(obj + " " + obj2); }}

e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}

What will be the output of the following Java program?class java   {    public static void main(String args[])    {      int var1 = 3;       int var2 = 8;      if ((var2 = 2) == var1)        System.out.print(var2);      else         System.out.print(++var2);    }   }Options3421

What is the output of this program? class Output  {       public static void main(String args[])  {              int a1[] = new int[10];              int a2[] = {1, 2, 3, 4, 5};              System.out.println(a1.length + " " + a2.length);       } }Select one:a.0 5b.10 5c.5 10d.0 10

What is the Output of following Java Program?abstract class Demo{    public int a;    Demo()    {        a = 10;    }     abstract public void set(); }class Test extends Demo{     final public void get()    {        System.out.println("a = " + a);    }     public static void main(String[] args)    {        Test obj = new Test();        obj.get();    }}Select one:a.Compile Time Errorb.a=10c.Runtime Exception

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.