JAVA程序设计-答案 联系客服

发布时间 : 星期二 文章JAVA程序设计-答案更新完毕开始阅读d3c2a41d10a6f524ccbf852b

34.若子类和父类在同一个包中,则子类继承父类中的(public)、(protected)和(默认)成员,将其作为子类的成员,但不能继承父类的(private)成员。

35,将其作为子类的成员,但不能继承父类的(默认)和(private)成员。

36.(子类对象)直接赋值给(父类对象)时,子类对象可自动转换为父类对象,(父类对象)赋值给(子类对象)时,必须将父类对象强制转换为子类对象。

37.Java的多态性主要表现在(方法重载)、(方法覆盖)和(变量覆盖)三个方面。 38.重写后的方法不能比被重写的方法有(更严格)的访问权限,重写后的方法不能比被重写的方法产生更多的异常。

39.Java语言中,定义子类时,使用关键字(extends)来给出父类名。如果没有指出父类,则该类的默认父类为(Object类)。

40.Java语言中,重载方法的选择是在编译时进行的,系统根据(参数个数)、(参数类型)和参数顺序寻找匹配方法。

41.实现接口中的抽象方法时,必须使用(完全相同)的方法头,并且还要用(public)修饰符。

42.接口中定义的数据成员均是(常量数据成员),所有成员方法均为(抽象方法)方法,且没有(构造)方法。

43.this代表(当前对象自身)的引用,super表示的是当前对象的直接父类对象。 44.如果一个类包含一个或多个abstract方法,则它是一个(abstract)类。

45.Java不直接支持多继承,但可以通过(接口)实现多继承。类的继承具有(传递)性。

46.没有子类的类称为(最终类),不能被子类重载的方法称为(最终方法),不能改变值的量称为常量,又称为(最终变量)。

47.一个接口可以通过关键字extends来继承(多个)其他接口。

48.接口中只能包含(public static final)类型的成员变量和(public abstract)类型的成员方法。

49.一般地,内部类又分为定义在方法体外的(成员类)和定义在方法体内的(局部类)两种。

50.静态内部类可直接通过外部类名引用,其一般格式是(new 外部类名.内部类构造方法( );)。

四、分析题(每题10分,共10题)

1.分析下面的程序,写出运行结果。 public class Exercises5_1 {

String str = new String(\ char[] ch = { 'L', 'i', 'k', 'e' };

public static void main(String args[]) { Exercises5_1 ex = new Exercises5_1(); ex.change(ex.str, ex.ch);

System.out.print(ex.str + \System.out.print(ex.ch);

}

public void change(String str, char ch[]) {

str = \ ch[1] = 'u';

} }

运行结果是:( Hi ! Luke ) 2.分析下面的程序,写出运行结果。 public class Exercises5_2 {

public static void main(String[] args) { int n = 1, m, j, i;

for (i = 3; i <= 30; i += 2) { m = (int) Math.sqrt((double) i); for (j = 2; j <= m; j++) if ((i % j) == 0) break;

if (j >= m + 1) { System.out.print(i + \ if (n % 5 == 0) System.out.print(\ n++;

}

}

}

}

运行结果是:( ) 3 5 7 11 13

17 19 23 29

3.分析下面的程序,写出运行结果: public class Exercises5_3 {

public static void main(String args[]) {

String str1 = new String();

String str2 = new String(\

char chars[] = { 'a', ' ', 's', 't', 'r', 'i', 'n', 'g' }; String str3 = new String(chars);

String str4 = new String(chars, 2, 6);

byte bytes[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, String str5 = new String(bytes);

StringBuffer strb = new StringBuffer(str3);

System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\

0x39 };

}

}

运行结果是:( ) The String str1 is

The String str2 is String 2 The String str3 is a string The String str4 is string

The String str5 is 0123456789 The String strb is a string

4、分析下面的程序,写出运行结果。 import java.awt.*; import java.applet.*; class MemberVar { static int sn = 30; final int fn; final int fk = 40; MemberVar() { fn = ++sn; } }

public class Exercises5_1 extends Applet { public void paint(Graphics g) {

MemberVar obj1 = new MemberVar(); MemberVar obj2 = new MemberVar();

g.drawString(\ g.drawString(\ g.drawString(\ g.drawString(\ }

}

运行结果是:( ) obj1.fn=31 obj1.fk=40 obj2.fn=32 obj2.fk=40

5.分析下面的程序,写出运行结果。

public class Exercises6_1 extends TT{ public void main(String args[]){

Exercises6_1 t = new Exercises6_1(\ }

public Exercises6_1(String s){ super(s);

System.out.println(\

}

public Exercises6_1(){ this(\ } }

class TT{

public TT(){

System.out.println(\ }

public TT(String s){ this();

System.out.println(\ } }

运行结果是:( ) What a pleasure! I am Tom

How do you do?

6.分析下面的程序,写出运行结果。 public class Exercises6_2 {

private static int count; private String name; public class Student { private int count;

private String name;

public void Output(int count) { count++;

this.count++;

Exercises6_2.count++;

Exercises6_2.this.count++;

System.out.println(count + \this.count + \ + Exercises6_2.count + \

ses6_2.this.count++);

}

}

public Student aStu() { return new Student(); }

public static void main(String args[]) { Exercises6_2 g3 = new Exercises6_2();

g3.count = 10;

Exercises6_2.Student s1 = g3.aStu(); s1.Output(5);