Do I have to use “package” term in every class?

前端 未结 4 642
耶瑟儿~
耶瑟儿~ 2020-12-15 06:49

Firstly, I\'m trying to learn Java with Java, A Beginner\'s Guide, 4th Edition. I use Ubuntu as my OS and Netbeans as my IDE. I need to create a project to

4条回答
  •  温柔的废话
    2020-12-15 07:31

    No you don't need to put in a package into your class UNLESS you are going to import it to another class that will be in it's own file. This is where protected type variables come in when you don't want to make them priviate but only want the subclasses (or child classes) access to them. You are also missing your public statement for your class so it should look like

    public class First{
        public static void main(String[] args){
              System.out.println("Hello!");
           }
    
    
    }
    

提交回复
热议问题