// store this file in a file class2.java. In the same directory // store the file for class1.java. In the same directory, // keep the package Gemetry. // You compile class2.java and execute it without problem // Whereas if you make the method Mid_point() in // class1.java "non-static", you won't be able to compile // class2.java. This is because only static methods and attributes // are accessile to the static main method of class class2.java // It is idvisable to keep a method static if it is not // defined to work on a specific object. So it is a bad programming // practise if we make the method Mid_point non-static in the file // class1.java. But if we have to use such a non-static method, // we shall have to create an object of class class1 and // then execute the method on the object. // The moral of the entire discussion is the following // ----------------------------------------------------------- // 1. when you are designing a method which will be for entire // class and not for a specific object, you better declare it static. // Otherwise, you declare it as non-static. // 2. A static method is accessed by class_name.method_name. // 3. A non-static method is accessed by reference_variable.method_name. // // These points should hopefully resolve most of your confusion. // If you still have any doubts, please ask them in extra class // to be held on 28September from 10:00 AM to 11:30AM in CS101. // import Geometry.Point; class class2 { public static void main(String args[]) { Point P = new Point(4,4); Point Q = new Point(4,0); Point R = new Point(0,2); Point mid = class1.Mid_point(P,Q); double d = R.distance_from_point(mid); System.out.println("Distance of R from mid point of P and Q :"+d); } }