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.

No comments:

Post a Comment

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...