Examveda
Examveda

Given the following piece of code:
class Person{
        public int number;
}
public class Test{
        public void doIt(int i , Person p){
                i = 5;
                p.number = 8;
        }
        public static void main(String args[]){
                int x = 0;
                Person p = new Person();
                new Test().doIt(x, p);
                System.out.println(x + " " + p.number);
        }
}

What is the result?

A. 0 8

B. 5 0

C. 0 0

D. 5 8

Answer: Option A


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

Comments ( 2 )

  1. Pratima Kumari
    Pratima Kumari :
    4 years ago

    What is the flow of execution

  2. Deep Mahour
    Deep Mahour :
    7 years ago

    Can someone explain the result?

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