I am trying to access private data members from one class in another class..
eg: Trying to use a print() method in one class and trying to access the data members with getID()..
However this throws and error "Non static method cannot be referenced from static context.."
What have I done wrong and how could I correct it? Code snippets below..
Part of my print()
Part of my CD classCode:public void inorderPrint() { if (left != null) left.inorderPrint( ); System.out.print(CD.getID()+"\t"); if (right != null) right.inorderPrint( ); }
Thankyou for your time..Code:public class CD { private int ID; private String artist; private String title; private String company; /** Creates a new instance of CD */ public CD(int id, String ar, String ti, String co) { ID = id; artist = ar; title = ti; company = co; } public int getID() { return ID; } public String getArtist() { return artist; } public String getTitle() { return title; } public String getCompany() { return company; } }


Reply With Quote




Bookmarks