filmov
tv
Different FileName & ClassName Java Program Executed 100% Logically Possible || Common Java Myth

Показать описание
#DeepCodecGuru #AjayPrasadKushwaha #AitamBuzzClub The myth about the file name and class name in Java
The first lecture note given during java class is “In java file name and class name should be the same”. When the above law is violated a compiler error message will appear as below
filter_none
edit
play_arrow
brightness_4
public class Geeks
{
public static void main(String[] args) {
}
}
Output:
public class Geeks
^
1 error
But the myth can be violated in such a way to compile the above file.
filter_none
edit
play_arrow
brightness_4
class Geeks
{
public static void main(String[] args) {
}
}
Step 2: java Geeks
Now the output will be Hello world
The myth about the file name and class name should be same only when the class is declared in
public.
The above program works as follows :
javaex
Now this .class file can be executed. By the above features some more miracles can be done. It is possible to have many classes in a java file. For debugging purposes this approach can be used. Each class can be executed separately to test their functionalities(only on one condition: Inheritance concept should not be used).
But in general it is good to follow the myth.
Follow me on:
Yours,
Ajay Prasad Kushwaha
(AITAM-BUZZ Club’s Founder-President, II CSE-A)
The first lecture note given during java class is “In java file name and class name should be the same”. When the above law is violated a compiler error message will appear as below
filter_none
edit
play_arrow
brightness_4
public class Geeks
{
public static void main(String[] args) {
}
}
Output:
public class Geeks
^
1 error
But the myth can be violated in such a way to compile the above file.
filter_none
edit
play_arrow
brightness_4
class Geeks
{
public static void main(String[] args) {
}
}
Step 2: java Geeks
Now the output will be Hello world
The myth about the file name and class name should be same only when the class is declared in
public.
The above program works as follows :
javaex
Now this .class file can be executed. By the above features some more miracles can be done. It is possible to have many classes in a java file. For debugging purposes this approach can be used. Each class can be executed separately to test their functionalities(only on one condition: Inheritance concept should not be used).
But in general it is good to follow the myth.
Follow me on:
Yours,
Ajay Prasad Kushwaha
(AITAM-BUZZ Club’s Founder-President, II CSE-A)