Hello Nisheeth,
You have a file name called "MyClass.java" in your current directory. That is the reason why you are getting no compile time or runtime errors. So, just remove that statement from your code or rename the already existing
java file "MyClass.java" from your current directory, to something else if you intend to do anything with your "MyClass".
The rest of the thing is understood. As you have a method which is changing the label. If you still have any doubts give print statements where ever you have doubt. That should clear your doubts.
If you are still not clear, let the ranchers know. They will get it done.
Originally posted by Nisheeth Kaushal:
Hi all,
Look at the code below-
import java.awt.*;
class changeLabelThruThis {
public changeLabelThruThis(){
Button b = new Button("Before");
this.changeLabel(b);
System.out.println(b.getLabel());
}
public static void main(String [] arg){
changeLabelThruThis mc = new changeLabelThruThis();
MyClass mc1 = new MyClass(); // <== this line
}
public void changeLabel(Button c){
c.setLabel("After");
}
}
Can anyone sugget why the output is "After" even if the b reference is set to "Before" and why the highlighted line in not flagging any error.
please reply urgently.
Nisheeth