1.

When a class file gets created in Java?

Answer»

The JAVA CLASS file has a .class extension and contains the Java bytecode. This class file can be executed by the Java Virtual Machine.

The Java 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.

A program that demonstrates the creation of a class file in Java is given as FOLLOWS:

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

The output of the above program is as follows:

This is class A This is class B

After the above program is compiled successfully, there are 3 class files created in the corresponding folder as there are 3 CLASSES in the .java file. These class files are A.class, B.class and Demo.class.



Discussion

No Comment Found