+ 1
Is it necessary to same the file name and class name in the Java applet program?
7 odpowiedzi
+ 3
Gopal Agarwal No, I think not. But maybe it depends also on your IDE. In eclipse main method must be public.
And I am not sure if it would be a wise idea to make the main class private and to choose a different file name for the main class. (if it is possible at all)
+ 2
Gopal Agarwal Your main class have to be public. Other classes not. (If you normally use one class --> public / class = filename)
http://www.dmc.fmph.uniba.sk/public_html/doc/Java/ch8.htm
quote:
" Although your applet can have as many additional "helper" classes as it needs, it's the main applet class that triggers the execution of the applet. That initial applet class always has a signature like this:
public class myClass extends java.applet.Applet {
...
}
Note the public keyword. Java requires that your applet subclass be declared public. Again, this is true only of your main applet class; any helper classes you create do not necessarily need to be public. "
+ 2
Denise Roßberg
If i do this
The program will run but applet will not initialise
+ 1
If your file contains a public class, yes. File name and class name must be the same. No public classes --> not necessary.
https://www.geeksforgeeks.org/myth-file-name-class-name-java/amp/
+ 1
If the class does not public in program then the applet is not initialise.
Denise Roßberg
+ 1
Output will not appear in applet.
+ 1
Denise Roßberg
If I do not make main class public
And do not keep the file and class name the same.
Then will the program run ?