+ 1
Why this doesn't work?
package prueba2.pkg1; import javax.swing.*; /** * * @author J. */ public class Prueba21 { public class PestaƱa extends JFrame{ public PestaƱa(){ super("new windows"); setSize(1920,1080); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } /** * @param args the command line arguments */ public static void main(String[] args) { /* here it say that non-static variables can not be referenced from a static context, and i know that this is because the main i sstatic but the constructor no, but i don't know how to fix the problem */ PestaƱa W1 = new PestaƱa(); W1.setVisible(true); } }
1 Answer
+ 1
PestaƱa is an inner class of Prueba21.
You can seperate the two classes or use only one class.
static means the method or variable belongs to the class. and non static means it belongs to the instance (object).
Edit:
If you want to create an object from the inner class PestaƱa:
Prueba21 pr = new Prueba21();
PestaƱa W1 = pr.new PestaƱa();