- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
When can a .class file get created in Java?
A Java class file has a ".class" extension and contains the Java bytecode. This class file can be executed by the Java Virtual Machine (JVM). A ".class" file is created as a result of successful compilation by the Java compiler from the ".java" file. Each class in the .java file is compiled into a separate class file if the ".java " file has more than one class.
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 a successful compilation of a Java program, there are four ".class" files are created in the corresponding folder as there are four classes are defined in the "ClassTest.java" file. Those are A.class, B.class, C.class and ClassTest.class.
Output
This is class A This is class B This is class C
Advertisements