• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output for a Jave prog

 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi , The above code produces the following output


A1
A1
C3

Please explain how the above ouput is printed..What is the use of this()
 
Henry Wong
author
Marshal
Pie
Posts: 20886
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajiv Chelsea wrote:
What is the use of this()


OK, let's have a clue: this(args) call the overloaded constructor of the class. In your case this() calls the no-args constructor of the same class! Try it, you'll get it!
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this() is used call the another constructor (as per passed arguments) of the same class and super is used to call superclass constructor. What you have not understand in this?
 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all!
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
QuoteYourSources

If you post questions on JavaRanch, You have to tell us where you get them from.
 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got these from a scjp test engine i downloaded
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one?
 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I downloaded it from Khalid Mughals webpage
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic