Given: 10. class One { 11. public One() { System.out.print(1); } 12. } 13. class Two extends One { 14. public Two() { System.out.print(2); } 15. } 16. class Three extends Two { 17. public Three() { System.out.print(3); } 18. } 19. public class Numbers{ 20. public static void main( String[] argv) { new Three(); } 21. } What is the result when this code is executed?

  1. 1

  2. 3

  3. 123

  4. 321


Correct Option: C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 1 - This option is incorrect because it only prints the value 1, but the code will also print other values.

Option B) 3 - This option is incorrect because it only prints the value 3, but the code will also print other values.

Option C) 123 - This option is correct because the code creates an instance of the class Three in the main method. Since Three extends Two, which extends One, the constructors of One, Two, and Three will be called in that order. The constructors print 1, 2, and 3 respectively, resulting in the output 123.

Option D) 321 - This option is incorrect because it reverses the order of the printed values. The correct order is 123.

The correct answer is C. This option is correct because the code will print the values 1, 2, and 3 in that order, resulting in the output 123.

Find more quizzes: