Where will i put “Public static void main(String[] args)”?

前端 未结 4 1921
陌清茗
陌清茗 2021-01-17 00:54

I started coding java a few days ago. İ made a few succesfull programs but im stuck on this one. Where ever i write the \"Public static void main(String[] args)\" code i get

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 01:37

    Your Board() is actually a constructor, which cannot be created inside a method. Every class has a constructor. If one isn't coded, a default no-arg constructor is provided to you. The main problem you are facing is you are creating a constructor called Board inside a class called Panel_Test.

    To give you a basic example of how it works:

    public class Board extends JFrame {
    
        //your fields
    
        public Board() {//your constructor
    
        }
    
        //your methods
    
    }
    
    public class Test_Panel {
    
        public static void main(String[] args) {
    
            Board board = new Board();//calling your Test_Panel class' constructor 
    
        }
    
    }
    

    If you're new to programming and would like to become more solid with the basics, here's a nice website I've used on occasion when learning Java in my time as a programmer.

提交回复
热议问题