java - I have 2 classes in Bluej and want to make a field in one of the classes be of type of the other class. How would I do this? -
i have made 2 classes in project in bluej , have link them making new field in main class of type of second class.
what syntax this?
i may interpreting question wrong but, assuming classes class1 , class2, can have class1 take in instance of class2 so:
public class class1{ class2 otherclass; public class1(class2 otherclass){ this.otherclass = otherclass; } }
now class1 has instance of class2 can play with.
you may have class1 create class2 object instead of passing 1 so:
public class class1{ class2 otherclass; public class1(){ otherclass = new class2(); } }
Comments
Post a Comment