Does every program in Java require a class?

后端 未结 6 1197
臣服心动
臣服心动 2020-12-16 02:19

Every Java program requires the presence of at least one class.

Is the above statement always true ?

6条回答
  •  心在旅途
    2020-12-16 03:01

    JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
    so, it is compulsory to provide at least one class name to Java programs. ex--->`

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

    so, javac _____ ("Here we have to give the name of java program in which we save")

    java ______ ("Provide the name of a class which contain the main() method")

    -----> according to our program

    javac Hello (here I save the program name by Hello.java)

    java Test (because Test class contains main() method)

    Thank You

提交回复
热议问题