Reputation: 11
I am fairly new to java . This has reference to passing-reference-of-class-to-another-class. Can some one explain AedonEtLIRA reply with real life example? It is really confusing
Upvotes: 0
Views: 817
Reputation: 143074
Here's a more concrete version of the example in the answer in question:
class Door {
public Door() {
Doorknob knob = new Doorknob(this);
}
}
class Doorknob {
public Doorknob(Door creator) {...}
}
Here, creating a Door creates a Doorknob, and the Doorknob knows about the door that created it.
I think the most confusing thing about the original example was that he named the classes "ClassA" and "ClassB" which makes it sound like these classes represent classes. There's no "passing reference of class to another class" going on here, but rather passing a reference to an instance of one class to the constructor of the instance of another class.
Upvotes: 3
Reputation: 469
As you can see at the link you provided, there is already a chosen answer. If you don't understand it, the problem is not java, but classes. Learn object oriented design, you can search java object oriented tutorial. Or you can start here http://docs.oracle.com/javase/tutorial/java/concepts/
Upvotes: 0