java variable scope - use of "this" keyword
I cannot get the following piece of code to behave. The test file I am using passes the string "hello" to SimpleEmail, nut the output that I get is "unknown", which means that when I use "this.(variablename)", it is actually accessing the global variable, and not the local one. Any help would be greatly appreciated.
import java.io.*;
public class SimpleEmail
{
public static String sender = "unknown", recipient = "unknown", subject = "unknown", content = "unknown";
public SimpleEmail(String sender, String recipient, String subject, String content)
{
sender = this.sender;
recipient = this.recipient;
subject = this.subject;
content = this.content;
System.out.println("sender =" + sender + " this sender = " + this.sender);
System.out.println("subject = "+ subject+" this subject = "+ this.subject);
}
}
|