Connect Classes in Java Application | Core Java Tutorial

This Core Java Tutorial  “Connect Classes in Java Application” post explains clearly how to connect more than one class in java application by accessing one class members from another class.


 

Connecting classes:

  • Every software is a set of programs.
  • Every java application is a collection of class files(objects).
  • Modularity is the concept of dividing complete application code into programs.
  • We can combine these programs by connecting them.

 

Can we define more than one class in a single source file?

  • Yes allowed.
  • Compiler generates class file for all the classes which are present in the source file.
  • It is recommended to define main() method inside a single class.
  • Every Java application is having single starting point(main method).
  • We must execute the class only which is having main method.
  • Following example describes clearly.

Define More than one Class in Java source file

 

  • JVM will not load un-used classes in the application.
  • As a programmer, we can analyze whether a class has loaded or not only by defining static block.
  • Static block executes implicitly at the time of class loading.

 

 

Share this