| Author |
Class and Java file
|
Thirumalai Muthu
Ranch Hand
Joined: Oct 07, 2007
Posts: 75
|
|
Hi, Why should the name of the Java file and the class having the main method be the same? Waiting for reply. Thanks
|
SCJP 5
|
 |
Dean Jones
Ranch Hand
Joined: Dec 29, 2007
Posts: 129
|
|
|
It is not a requirement, if the class is not marked public.
|
 |
Thirumalai Muthu
Ranch Hand
Joined: Oct 07, 2007
Posts: 75
|
|
I typed the above code in the notepad and named the file as b.java. The compile was successful but when the program was run I got a No Classdef exception. Can anyone explain why this is happening? Hi Dean you said that only if the class having the main method is marked public,then the file name and the class name should be same. I got that point. But my question is how do you compile the above "class a" which resides inside the file called "b.java" [ January 07, 2008: Message edited by: Thirumalai Muthu ]
|
 |
Ganesha Kumar
Ranch Hand
Joined: May 04, 2006
Posts: 56
|
|
|
When you compile b.java, the class that is generated is a.class. You have to run the class a. Then you don't get ClassNotFoundException.
|
 |
Thirumalai Muthu
Ranch Hand
Joined: Oct 07, 2007
Posts: 75
|
|
Ok Thanks ganesh I got it.
|
 |
 |
|
|
subject: Class and Java file
|
|
|