Given:
1. package geometry;
2. public class Hypotenuse {
3. public InnerTriangle it = new InnerTriangle();
4. class InnerTriangle {
5. public int base;
6. public int height;
7. }
8. }
Which is true about the class of an object that can reference the
variable base?
A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
1. package geometry;
2. public class Hypotenuse {
3. public InnerTriangle it = new InnerTriangle();
4. class InnerTriangle {
5. public int base;
6. public int height;
7. }
8. }
Which is true about the class of an object that can reference the
variable base?
A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
解决方案 »
- 这就是 JAVA的真面目
- JAVA中取mssql中的ntext时出错
- 请教各位高手,java 对硬件编程 支持如何?譬如:对IC卡读写器的操作 ?
- [求助]关于定时执行任务
- 一题目,对象是什么
- 我想做一个弹出式菜单,可是在添加监听的时候老是报错,请大家看一看。在线等……
- 新手请教,jbuilder运行时参数配置问题
- 庆祝加星,给大家几篇文章,顺便散分!!
- 问:当输入javac hellojava.java后,按回车,dos显示的是“javac不是内部或外部命令,也不是可运行程序或批处理文件.",这是咋回事?
- JNI 中内存管理的问题
- java学习快一年了,想问问高手的意见
- 这是个麻烦的序列,将如何实现?
有待高手解析。
B没有类是基类的子类,不对,任何类都是object的子类
C没错,是属于geometry,因为第一句package geometry
D没有任何extends语句,也只有一个内部类InnerTriangle,所以是Hypotenuse的子类错误
代码如下:同一个包pack包下的非继承类也能够访问,故D错:package pack;public class Temp {
public Inner it = new Inner();
class Inner{
public int base;
public int height;
}
}package pack;public class Test {
public static void main(String[] args){
Temp tem = new Temp();
int a = tem.it.base;
}
}另一个包pack1 下测试,访问不到,编译期报错:package pack1;import pack.*;public class Test {
public static void main(String[] args) {
Temp tem = new Temp();
//error: The type Temp.Inner is not visible
int a = tem.it.base;
}
}
PS:这种问题其实自己跑一下程序就出来了