MCQ Practice Single Best Answer Topic: Java Constructor and Methods

Q 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?

Question ID
#2182
Subchapter
Java Constructor and Methods
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A 0 8
  • B 5 0
  • C 0 0
  • D 5 8
Correct Answer: A

Explanation

0 8

Share This Question

Share this MCQ with your friends or study group.