java - 请让我知道如何在 java 的构造函数中将值作为 3 级传递?
问题描述
这是我的主要功能。
class first{
public static void main(String ar[]){
second sc = new second();
}
}
class second{
second(third th){
this.th = th;
}
}
class third{
private int i;
third(int i){
this.i = i;
}
}
请在不更改构造函数参数的情况下告诉我解决方案。我不知道如何传递构造函数以及如何将构造函数的参数作为类的对象给出。
解决方案
在构造函数的参数中调用构造函数second
(或首先创建一个变量并传递它)
second sec = new second(new third(12));
推荐阅读
- python - 如何在 tensorflow 自定义训练循环中考虑 l1 和 l2 正则化器?
- javascript - 客户端和服务器之间需要多少通信才能进行 JWT 验证?
- java - 如何使用尾递归和/或流来查找字符串的所有排列,而不会耗尽长字符串的内存
- mysql - MySQL Workbench - 表数据导入向导将所有日期时间对象写入 0000-00-00 00:00:00
- python-3.x - 如何检测是否已将唯一条目添加到数组中,并使用基于该唯一条目的输入附加到它?
- c# - CQRS 架构模式中的查询处理程序
- google-cloud-platform - 谷歌云机器上的领事
- python - 有没有办法在 sklearn 管道中链接 pd.cut FunctionTransformer?
- python - 在 ThreadPoolExecutor.map() 中传递多个参数
- javascript - 对于aws serverless,如果我想将图片上传到端点,如何获取图片文件的名称?