June 25, 20169 yr You either have to make that object from that class and call it, e.g //Other file: Class Thing { String name; public String getName(){ ... } } // Main Class main{ public static void main(){ Thing thing = new Thing(); System.out.println(" My name is " + thing.getName() } } Or make the method static, e.g When you have a static method it is saying that you do not need to create an instance of this object to use the method. Thus static methods cannot use fields from it's the class, so they usually take input. //Other file: public Thing{ public static String getName(){ return "John"; } } // Main public static void main(){ String name = Thing.getName(); System.out.println("My name is" + name); } Edited June 25, 20169 yr by Qubit
Create an account or sign in to comment