
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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
- Related Articles
- Can a final variable be initialized when an object is created in Java?
- How can I restore a file created by mysqldump?
- How many ways can get the instance of a Class class in Java?
- Why do we get ClassNotFoundException when the class exists in Java?
- Display File class constants in Java
- How static class Object is created without reference of outer class in java?
- When can we use intern() method of String class in Java?
- Get Absolute path of a file in Java
- How to use file class in Java?
- How many ways a String object can be created in java?
- Get file extension name in Java
- Writing data to a file using BufferedWriter class in Java
- Get Canonical Name for a class in Java
- When does a NullPointerException get thrown in java?
- Can you change size of Array in Java once created?

Advertisements