Home > Java > javaTutorial > body text

In Java, when is a .class file created?

王林
Release: 2023-08-27 11:41:10
forward
870 people have browsed it

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();
   }
}
Copy after login

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 < /strong> 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
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template