Java程序设计(华东交通大学)章节测试答案
2025年11月21日
2025年11月21日
class Person { private int a; public int change(int m){ return m; } } public class Teacher extends Person { public int b; public static void main(String arg[]){ Person p = new Person(); Teacher t = new Teacher(); int i; // point x } } 在 // point x安排哪个语句合法? A.i = b; B.i = m; C.i = p.a; D. i = p.change(30);
class Person { p...
2025年11月21日
设有如下代码段 1 String s = null; 2 if ( s != null & s.length() > 0) 3 System.out.println(“s != null & s.length() > 0”); 4 if ( s != null && s.length() > 0) 5 System.out.println(“s != null & s.length() > 0”); 6 if ( s != null || s.length() > 0) 7 System.out.println(“s != null & s.length() > 0”); 8 if ( s != null | s.length() > 0) 9 System.out.println(“s != null | s.length() > 0”); 哪些行将抛出空指针异常? 假设在检查过程中把抛出异常的if语句注释掉继续验证. A.2,4 B.2,4,6,8 C.2,6,8 D.6,8
设有如下代码段 1 String...
2025年11月21日
2025年11月21日
考虑如下代码,其中包括一个内嵌类:public final class Test4 { class Inner { void test() { if (Test4.this.flag) { sample(); } } } private boolean flag = false; public void sample() { System.out.println(“Sample”); } public Test4() { (new Inner()).test(); } public static void main(String args []) { new Test4(); }}结果为? A.程序编译失败 B.程序无输出,但正确终止 C.程序不能终止 D.输出 “Sample”
考虑如下代码,其中包括一个内嵌类...