• 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

this

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assalam O Alekum:
i have problem in this keyword.
public class MyClass{
public MyClass(){
this("hello); // why this keyword write the first line.
SOP("thanks");
}
public MyClass(String str){
SOP(str);
}
}
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by asif zia:
Assalam O Alekum:
i have problem in this keyword.
public class MyClass{
public MyClass(){
this("hello); // why this keyword write the first line.
this or super if used in the constructor should be the first line
here we are calling the other constructor of the current class which takes a string as a parameter. (that is the constructor
public MyClass(String str)
hope it is clear
SOP("thanks");
}
public MyClass(String str){
SOP(str);
}
}


 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Asif,
The keyword this is used here because it calls the constructor
marked '2' please see my code below.

Hope this clarifies the issue.
Ravindra Mohan.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic