Examveda
Examveda

Determine output:
public class Test{
      public static void main(String args[]){
            MyClass obj = new MyClass();
            obj.val = 1;
            obj.call(obj);
            System.out.println(obj.val);
      }
}

class MyClass{
      public int val;
      public void call(MyClass ref){
            ref.val++;
      }
}

A. 1

B. 2

C. 3

D. Compilation Error

E. None of these

Answer: Option B


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

Comments ( 2 )

  1. Pavan Kumar
    Pavan Kumar :
    3 years ago

    Pls explain this program

  2. Khushboo Pandya
    Khushboo Pandya :
    7 years ago

    how

Related Questions on Constructors and Methods

What is a constructor in Java?

A. A special method to create instances of classes

B. A method used for mathematical calculations

C. A method to perform string manipulations

D. An exception handling mechanism