如何通过返回类对象来将一个类对象变量固定在另一类中? [英] How can fixed one class object variable in another class by returning class object ?

查看:78
本文介绍了如何通过返回类对象来将一个类对象变量固定在另一类中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例,

Example,

class loan{
       private String name;
       private String id;
       private String address; 
//.. ... ..
// ... ... ..
//... ... ...

}


class librarian{
private String name;
private String id;
private String address;

public loan input_loan{
// .. .
//... ... ...
//... ... ...

return l1;

}
}



不是在主要类中,而是在两个没有继承的类中?



Not in main but in two different class without inheritance?
please if you have solution do it here.

推荐答案

不是100%肯定这是您要的内容,但似乎无法实例化库管理器类的方法中有一个新的借阅对象,因此您可以从该方法返回借阅对象?

如果是这样,那么您所缺少的就是这个:

Not 100% sure this is what you''re asking, but it looks like you''re having trouble instantiating a new loan object from within a method of the librarian class so you can return the loan object from the method?

If so, the piece you''re missing is this:

loan l1 = new loan();



用该代码实例化贷款后,可以调用贷款的设置器(您拥有我信任的设置者)来初始化贷款.

请注意,如果图书管理员和借贷类位于不同的包中,则需要在librarian.java中导入包含借贷类的包!



After you instantiate the loan with that code, you can then call setters on the loan (you have those I trust?) to initialize the loan.

Note that if the librarian and loan classes are in different packages, you will need to import the package containing the loan class in librarian.java!


这篇关于如何通过返回类对象来将一个类对象变量固定在另一类中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆