public class Second { public static void main(String[] args) { Main obj = new Main(); System.out.println("Value of x is" + obj.x); // 5 } } // object created for main class to beacuse we want to access the members of main class in second class.