• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help on constructor

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
A. snootchy 420 third second first
B. snootchy 420 first second third
C. first second third snootchy 420
D. third second first siiootchy 420
E. third first second snootchy 420
F. first second first third snootchy 420
Answer: D

Ned help to understand the answer
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dinesh Tahiliani:
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?
A. snootchy 420 third second first
B. snootchy 420 first second third
C. first second third snootchy 420
D. third second first siiootchy 420
E. third first second snootchy 420
F. first second first third snootchy 420
Answer: D

Ned help to understand the answer




main: Bootchy b = new Bootchy(); -> call to Bootchy() constructor
Bootchy(): this(�snootchy�); -> call to Bootchy(String snootch) constructor
Bootchy(String snootch) : this(420, �snootchy�); -> call to Bootchy(int bootch, String snootch) constructor
Bootchy(int bootch, String snootch): System.out.print(�third �); -> go back to Bootchy(String snootch) where System.out.print(�second �); -> go back to Bootchy() where System.out.print(�first �); -> go back to main where System.out.print(b.snootch +� � + b.bootch);
 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply
 
reply
    Bookmark Topic Watch Topic
  • New Topic