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.
- 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.
- 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.
Connecting classes in java
System.out.println("Login page is loading....");
public static void main(String args)
Inbox.mailInfo(); // This statement leads to load class
System.out.println("Inbox page is loading....");
static void mailInfo()
System.out.println("Recent mail info.....");