-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHello.java
More file actions
56 lines (46 loc) · 1.81 KB
/
Copy pathHello.java
File metadata and controls
56 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Phase0_SetupAndFirstPrograms.ClassNameMyth;
/**
* <h1>The Class Name Myth</h1>
*
* <h2>The Final Conclusion</h2>
* <p>Whether a Java source file compiles depends on the relationship between the
* class name, the file name, and whether the class is declared <code>public</code>.
* There are three cases to consider.</p>
*
* <ul>
* <li>If the class is <code>public</code> and the file name is the same as the
* class name, then it works fine.</li>
* <li>If the class is <code>public</code> and the file name is different from the
* class name, then it throws an error — the class name and file name
* must be the same.</li>
* <li>If the class is not <code>public</code> and the file name is different from
* the class name, then it still works fine.</li>
* </ul>
*
* <p>The programs demonstrating each case are shown below.</p>
*
* @author Deepak Gupta
* @version 1.0
* @since 2026-05-21
*/
/*public class Hello {
public static void main(String[] args) {
System.out.println("In This case Class Name and File name are Same.");
// OUTPUT
// In This case Class Name and File name are Same.
}
}*/
/*public class Overview.ClassNameMyth.HelloWorld {
public static void main(String[] args) {
System.out.println("In This case Class Name and File name are different.");
// OUTPUT
// Error:(13, 8) java: class Overview.ClassNameMyth.HelloWorld is public, should be declared in a file named Overview.ClassNameMyth.HelloWorld.java
}
}*/
class HelloWorld {
public static void main(String[] args) {
System.out.println("In This case Class Name and File name are different but the class is not public.");
// OUTPUT
// In This case Class Name and File name are Same but the class is not public.
}
}