Home  >  Article  >  Java  >  In Java, when is a .class file created?

In Java, when is a .class file created?

王林
王林forward
2023-08-27 11:41:10869browse

In Java, when is a .class file created?

Java class files have a ".class" extension and contain Java bytecode. This type of file can be executed by Java Virtual Machine (JVM). The Java compiler creates the ".class" file after successful compilation from the ".java" file. If a ".java" file contains multiple classes, each class in the .java file is compiled into a separate class file.

Example

class A {
   A() {
      System.out.println("This is class A");
   }
}
class B {
   B() {
      System.out.println("This is class B");
   }
}
class C {
   C() {
      System.out.println("This is class C");
   }
}
public class ClassTest {
   public static void main(String[] args) {
      A obj1 = new A();
      B obj2 = new B();
      C obj3 = new C();
   }
}

In the above example, after the Java program is compiled successfully, four ".class" files will be created in the corresponding folder, because there are The four classes are defined in the "ClassTest.java" file. They are A.class, B.class, C.class and ClassTest.class.

Output

This is class A
This is class B
This is class C

The above is the detailed content of In Java, when is a .class file created?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete