Why this doesn't work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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); } }

3rd Apr 2020, 1:16 PM
jared mijail
jared mijail - avatar
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();
3rd Apr 2020, 1:28 PM
Denise Roßberg
Denise Roßberg - avatar