Given: 11. public class Bootchy { 12. int bootch; 13. String snootch; 14. 15. public Bootchy() { 16. this(”snootchy”); 17. System.out.print(”first “); 18. } 19. 20. public Bootchy(String snootch) { 21. this(420, “snootchy”); 22. System.out.print(”second “); 23. } 24. 25. public Bootchy(int bootch, String snootch) { 26. this.bootch = bootch; 27. this.snootch = snootch; 28. System.out.print(”third “); 29. } 30. 31. public static void main(String[] args) { 32. Bootchy b = new Bootchy(); 33. System.out.print(b.snootch +“ “ + b.bootch); 34. } 35. } What is the result?

  1. snootchy 420 third second first

  2. snootchy 420 first second third

  3. first second third snootchy 420

  4. third second first siiootchy 420

  5. third first second snootchy 420

  6. first second first third snootchy 420


Correct Option: D

AI Explanation

To determine the result of the given code, let's analyze the code step by step:

  1. Line 32: Bootchy b = new Bootchy();
  • This line creates a new instance of the Bootchy class and assigns it to the variable b.
  • Since no arguments are passed, it invokes the default constructor public Bootchy().
  1. Line 15: public Bootchy()

    • This is the default constructor.
    • It calls the constructor this("snootchy");.
    • It prints "first ".
  2. Line 20: public Bootchy(String snootch)

    • This constructor takes a String parameter snootch.
    • It calls the constructor this(420, "snootchy");.
    • It prints "second ".
  3. Line 25: public Bootchy(int bootch, String snootch)

    • This constructor takes an int parameter bootch and a String parameter snootch.
    • It assigns the values of bootch and snootch to the respective instance variables.
    • It prints "third ".
  4. Line 33: System.out.print(b.snootch + " " + b.bootch);

    • This prints the value of b.snootch (which is "snootchy") followed by a space, and then the value of b.bootch (which is 0, as it was not explicitly assigned).

Based on the above analysis, the result of the given code is:

D. third second first siiootchy 420

Find more quizzes: