Trying to Cover Basic Concept :
1) A JAVA program contain any number of classes, but at most one class can be declared as public.
2) If there is public class, then the name of program and the name of the public class must be matched other-wise we get compile time error.
3) There is no relation of Main() method & name of the JAVA file.
When you write class without main() method. It will compile fine.
But when you run the code it will give error :
NoSuchMethodError : main
Example :
Test.java
class A(){
public static void main(String args[]){
System.out.println("In class Main : A");
}
}
class B(){
public static void main(String args[]){
System.out.println("In class Main : B");
}
}
class C(){
public static void main(String args[]){
System.out.println("In class Main : C");
}
class D(){
}
--------------------------------
Javac Test.java
--> No Compile Time Error you will get
Java A
o/p : In class Main A
Java B
o/p : In class Main B
Java C
o/p : In class Main C
Java D
o/p : NoSuchMethodError : main
Java Test
o/p : NoClassdefFoundError : Test
--> Run Time error you will get.
When you create JAR file or any package built. There is no need of main() method because you import the package or .Jar file and you call those method() in the working class.
When you run the application and want to automatically get the output. The public static void main(String[] args)
method is the signature where the compiler find the entry point of the program.
The code your professor uploaded is just a Class. It will compile fine.
From above code you can have a many main() methods in same file. But you have to run specific class.
Try to run Student class : you will get an Error: Main method not found in class Student, please define the main method as:
public static void main(String[] args)
main
, and you write what are essentially libraries or plugins for your application.