Dear frns, examine the code below carefully and just tell wethet it will compile.
yes the code above will compile !!Zapped !!! YES A FULLY EMPTY FILE IS A VALID SOURCE FILE AND COMPILES WITHOUT ANY ERROR can any one give me a logical explanation? also A Java file without any class or interface definitions can also be compiled. AMIT
Amit, See whether you get any class file when you compile an empty file. You don't get any. That means there is nothing to compile. To answer your second part, in Java, everything has to be in a class. You can not have free standing methods or variables as in C. If you have some variable or method not inside any class, then compiler issues this error message: Class or interface declaration expected Ramesh.
Dear Amit: The Java Language Specification basically says that a Java source file consists of the following 3 parts: 1. An OPTIONAL package statement 2. ZERO or more import statements 3. ZERO or more class definitions Therefore, there's nothing stopping you from compiling successfully an empty source file (of course, it's absolutely useless -- but that's another matter entirely). Hope that helps.
Whoever got anywhere by being normal? Just ask this exceptional tiny ad: