java - 我怎样才能使用这个变量?
问题描述
我想在主类中使用这个变量(ntime [])我想我必须使用'extends',但我不知道我是如何使用它的。我可以使用什么变量,以及如何使用它?我想知道它正在使用扩展,或者它可以使用其他变量。谢谢
我正在使用 extends ~~ void main(String args[]) extends * throws IOException & ~~ void main extends * (String args[]) *** throws IOException
但这行不通
导入 java.util.Calendar;
class *****
{
public void ***** throws IOException
{
int [] ntime = new int [6];
BufferedReader inbr = new BufferedReader (new
InputStreamReader(System.in));
Calendar now= Calendar.getInstance();
ntime[0] = now.get(Calendar.YEAR);
ntime[1] = now.get(Calendar.MONTH);
....
ntime[5] = now.get(Calendar.SECOND);
}
}
class ***** {
public static void main(String args[]) throws IOException
{
***** objecta = new ***();
objecta.test01();
System.out.println("Time is " + ntime[0] + ... + ntime[5]);
}
}
符号:变量 ntime 位置:类 ***
解决方案
由于 ntime 是 *** 类的成员。
为了能够访问它,您必须首先创建该类的实例并确保 ntime 不是私有成员。我认为您在创建“objecta”时所做的。然后您将不得不通过该对象访问您的变量 ntime 。
例如你会打电话
objecta.ntime[0]
推荐阅读
- html - 如何在网格中链接图像
- django - self.request.user 在 Django REST 框架中不起作用
- sql - 在 BIRT 中绘制线性回归线
- mysql - MySQL 查询以检索另一个表中的最后一个条目
- kotlin - 如何在 kotlin 中将扩展运算符与 ArrayList 一起使用?
- statistics - 在双边检验中比较显着性水平与 p 值
- laravel - Vue Props 数据数轮
- python - python中使用n输入的递归函数
- php - Laravel multiauth Gate 不适用于管理表
- azure-databricks - 重命名文件(附加时间戳)并将其移动到 ADLS Gen2(Databricks)上的不同文件夹