QuestionQ81

Java Object-Oriented Approach

Given:

Question Image

What is the resulting output?

  • A Sales - 102 is printed.Purchase - 102 is printed.
  • B Sales - 101 is printed.Purchase - 102 is printed.
  • D Sales - 102 is printed.Purchase - 103 is printed.
  • E Sales - 101 is printed.Purchase - 101 is printed.
Explanation

A static field is shared by every instance of a class. Starting from 100, the pre-increment expression ++dId produces 101 for the first Doc object and 102 for the second, so the two print calls use those respective values.

Community Discussion

No comments yet. Be the first to start the discussion!