Java learning : how many classes defined in java source, how many .class byte code files will be generated after compile via javac

One java source file generate one .class byte code file ?

False.
I thought one java source code file will generate only one .class byte code file, since I am a c++ programmer for about 10 years.
The correct answer is
how many classes defined in java source, how many .class byte code files will be generated after compile via javac
public class HelloWorld {
    class HelloInternal {
    }
}

enum HelloEnum {
}

interface HelloInterface {
}
javac HelloWorld.java
ls *.class
HelloEnum.class   HelloWorld$HelloInternal.class
HelloInterface.class  HelloWorld.class

Java classes

The classes can be any class, interface and enum.
All java codes should be placed in the classes.
otherwise you will get compile error
class, interface, or enum expected
In fact, enum is a class too, just a syntactic sugar.

Comments

Popular posts from this blog

react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

react-native run-android : do not build/update modified code(App.js)

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.