本学校计算机系java程序设计教学使用的教案
答:子类可以从父类继承除了构造函数之外的所有函数。当一个类实现一个接口时,它可以定义该接口中的所有方法。A,C正确。
31、 在如下源代码文件Test.java中, 哪个是正确的类定义? A、 public class test { public int x = 0; public test(int x) {
this.x = x; } }
B、public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C、public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D、 public class Test extends T1{ public int x=0; public Test(int x){ this.x = x; } }
E、protected class Test extends T2{ public int x=0; public Test(int x){ this.x=x; } }
答:在源代码文件Test.java中,类名必
须是Test, 不是test, 因为Java是大小写敏感的. 一个类不能有多个父类. 约束符protected不能放在类前。B,D正确。
32、 Person, Student 和Teacher 都是类名。这些类有以下继承关系。 Person |
--------------- | |
Student Teacher
并且在Java源代码中有如下表达式: Person p = new Student(); 如下哪个语句是正确的? A、 The expression is legal. B、The expression is illegal.
C、Some errors will occur when compile. D、Compile is correct but it will be wrong when running.
答:父类的指针也可指向子类。A正确。
33、 当Frame改变大小时,放在其中的按钮高度变化,宽度不变,则使用如下哪个layout?
A、 FlowLayout B、CardLayout
C、North and South of BorderLayout D、East and West of BorderLayout E、GridLayout
答:使用BorderLayout 的East和West。D正确。
34、 当Frame改变大小时,放在其中的按钮大小不变,则使用如下哪个layout? A、 FlowLayout B、CardLayout
C、North and South of BorderLayout D、East and West of BorderLayout E、GridLayout