File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this

 
asif zia
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
sona gold
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}

 
Ravindra Mohan
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic