aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "this" Watch "this" New topic
Author

this

asif zia
Greenhorn

Joined: Feb 10, 2001
Posts: 6
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

Joined: Feb 14, 2001
Posts: 234
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);
}
}


sona<br />SCJP
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
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
 
subject: this
 
Similar Threads
need answer
Why would this print true?
static methods can�t be overridden
Doubt in try and finally block execution.
Usage of Constant