Home > Back-end >  Java objects of one class to another class in the form of parameter of the method
Java objects of one class to another class in the form of parameter of the method

Time:09-21

If objects of one class to another class in the form of parameters of the method, then the latter can invoke the former public methods, and call all attributes for the incoming instance attributes,
If the former is the core engineering classes, often need to do this, can be in the latter the constructor of the incoming core class instances of them, and then add a core classes in the latter's attributes and initialized in the constructor, so that you can call at any time in the latter the former members of the function

CodePudding user response:

I want to ask the question is what?

CodePudding user response:

If such a mean?
@ Data
Public class A {

Private bInstance B;

BInstance public A (B) {
Enclosing bInstance=bInstance;
}

Public void methodOfA () {
BInstance. MethodOfB ();
}

Static class B {
Public void methodOfB () {
System. The out. Println (" this is a method in a class B ");
}
}
}
  • Related