Hi, I am new to Java, and I have the following questions (I was already looking for a forum, but have not figured it out yet):
Why is it possible to access private class variables from actionlistener as follows:
public class Test{ private int x; Test(){ init(); } .... public void init(){ .... Button button_1 = new Button("buttonTest"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { x++; } }); } }
And why can't I postpone the previous code (by creating the + actionlistener button) in the constuctor without errors ("x cannot be resolved")?
Hi
source share