第3部分SCJP认证试题-沈阳师范大学第3部分SCJP认证试题-沈阳师范大学
沈阳师范大学软件学院
OFTWARE COLLEGE OF SHENYANG NORMAL UNIVERSITY S
,第三版,
宋波 李晋 李妙妍 张艳丽 编写
姓名, 学号,
年级, 专业,
沈阳师范大学软件学院&软件工程系
前 言
本书是一本课后课后习题、SCJP试题的指导性教材~与《Java语言程序设计》,自编教材,配套使用。编写目的是通过一系列的上机实验与课后练习使学生理解并掌握所学的知识。作为一本教辅用书~希望读者把本书作为掌握知识的一个工具和桥梁~从而达到...
第3部分SCJP认证试题-沈阳师范大学
沈阳师范大学软件学院
OFTWARE COLLEGE OF SHENYANG NORMAL UNIVERSITY S
,第三版,
宋波 李晋 李妙妍 张艳丽 编写
姓名, 学号,
年级, 专业,
沈阳师范大学软件学院&软件工程系
前 言
本书是一本课后课后习题、SCJP试题的指导性
~与《Java语言程序
》,自编教材,配套使用。编写目的是通过一系列的上机实验与课后练习使学生理解并掌握所学的知识。作为一本教辅用书~希望读者把本书作为掌握知识的一个工具和桥梁~从而达到对Java语言语法
和的深入理解~提高读者的程序设计能力~并在学习的过程中不断发现问题、思考问题、解决问题。
本书共由二部分组成。第一部分为针对教材每一章的练习题~读者可以进行自测并掌握每一章的重点
。第二部分为Java国际认证,SCJP,典型试题~通过集中练习~可以使读者较快地掌握SCJP认证的内容~为顺利过关作好准备。
本书作为“软件学院重点课程建设”建设成果的一部分~由软件工程系的宋波老师组织编写~参加编写工作的有李晋、李妙妍和张燕丽等老师。本书的编写工作~自始至终得到软件学院的领导和软件工程系的大力支持~周传生教授和李航副教授对于本书的编写提出了宝贵的建议~本书也吸纳和借鉴了中外参考文献中的知识原理和资料~在此一并致以谢忱。
编者
2010年7月
目 录
第1部分:习题 ......................................................... 错误~未定义书签。
第1章:绪论 ...........................................................................................错误~未定义书签。
第2章:Java语言基础............................................................................................................. 1 第3章:Java面向对象特性..................................................................................................... 4 第4章:Java高级特征........................................................................................................... 11 第5章:异常处理 ................................................................................................................... 13 第6章:Java输入/输出.......................................................................................................... 16 第7章:AWT及AWT事件处理.......................................................................................... 18 第8章:Applet基础编程 ....................................................................................................... 21 第9章:Java多线程............................................................................................................... 22 第10章:Java网络程序设计................................................................................................. 23
第11章:JDBC技术 .............................................................................................................. 23
第2部分:SCJP认证试题....................................................................... 24
试题,: ................................................................................................................................... 24
: .................................................................................................................................... 36 试题2
第2章:Java语言基础
1. 已知“int i=33”,则指出下列的表达式哪一个是不正确的( )。
A byte b = i B long m = i
C double d = 3.14+i D int n = ++i
2(已知有下列声明语句“int i, j; float x, y; double u, v;”,则下列哪个赋值是合法的( )。
A i = x; B x=u+y; C x=7.8+j*y; D v=3.4+i*u;
3. 当执行以下程序片段后:“int i=1;int fox[]=new fox[3];int x=fox[i];x=x+i;”,x的值
为 。
4. 下面代码的输出结果为( )。
public class Sun {
public static void main(String args[]) {
int j=0;
for (int i=0; i<10; i++) {
j=i*10+6;
if (j%3!=0) {
continue; }
System.out.println( j );
}
}
}
5. 指出下列的表达式哪一个是正确的( )。
A boolean b=0 B float f=3.1415 C byte a=128 D int d=288
6. 假如“boolean a=true;int b=2,c=6”,则表达式a&&(b++%2==0)的值为 ,c+=c--/++b
的值为 。
7. 下面代码的输出结果为( )。
public class ForDemo {
public static void main(String args[]) {
outer: for(int i=1; i<3; i++) {
inner: for(int j=1; j<3;j++) {
if(j= =2)
continue outer;
System.out.println(“i=”+i+“j=”+j);
}
}
}
1
}
8. 假设“int x=10,y=20, z=30”,在表达式a=x>y?x:y-2中a的值
为 ,!(x
6)
break inner;
}
}
System.out.println("sum="+sum);
2
}
}
14. 下面程序是用do-while语句计算10的阶乘。请在每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其它已有的语句内容,仅在横线处填入适当的语句。
public class J_Test{
public static void main( ){
int n=10;
long result=1;
do{
}
System.out.println("10的阶乘为:"+result);
}
}
15. 设x=1,y=2,z=3,则表达式y+=z--/++x的值为( )。
A(3
B(3.5
C(4
D(5
16. 下列程序运行后,输出的结果是( )。
public class Test5{
public static void main(String[] args){
outer: for(int i=0;i<3;i++){ inner: for(int j=0;j<2;j++){
if(j==1) continue outer;
System.out.println(i+“and”+j);
}
}
}
}
A(0 and 0 B(0 and 1 C(1 and 0 D(0 and 0
1 and 0 0 and 1 1 and 1 1 and 1
2 and 0 0 and 2 1 and 2 2 and 2
17. 下列数组定义及赋值,错误的是( )。
A(int a[]={1,2,3,4,5};
B(int intArray[];
C(int intArray[]=new int[3];
intArray[1]=1;
intArray[2]=2;
3
intArray[3]=3;
D(int a[][]=new int[2][];
a[0]=new int[3];
a[1]=new int[4];
18. 下列程序执行以后,输出结果为( )。
public class Exam01 {
public static void main(String[ ] args) {
int x=5;
int y=2;
float m=2.5f;
m=m<=x%y?x-m:y-m;
System.out.println(m);
}
}
A(-0.5 B(-2.5 C(2.5 D(0.5
第3章:Java面向对象特性
1(下列关于变量作用域的描述中,不正确的一项是( )。 A(变量属性是用来描述变量作用域的。
B(局部变量作用域只能是它所在的方法的代码段。 C(类变量能在类的方法中声明。
D(类变量的作用域是整个类。
下面代码的输出结果为( )。 2(
class Parent {
void printMe( ) {
System.out.println("parent");
}
}
class Child extends Parent {
void printMe( ) {
System.out.println("child");
}
void printAll( ) {
super.printMe();
printMe();
}
}
public class TestThis {
4
public static void main (String args[ ]) {
Child myC=new Child( );
myC.printAll();
}
}
3(下列程序在编译以后,哪一行将引起一个编译时错误,( ) 1) public class Exam02 { 2) int m, n;
3) public Exam02() { } 4) public Exam02(int a) { 5) m=a;
6) }
7) public static void main(String arg[ ]) {
8) Exam02 t1,t2; 9) int j,k;
10) j=0;
11) k=0;
12) t1=new Exam02(); 13) t2=new Exam02(j,k); 14) }
15) }
A(line 3 B(line 7 C(line 8 D(line 13
4(下面代码的输出结果为( )。
class Father {
private int f1, f2;
public Father(int x, int y) {
f1=x;
f2=y;
}
public Father(int x) {
this(x, 0);
}
public void display( ) {
System.out.println(“f1=”+f1+“f2=”+f2);
}
}
class Son extends Father {
private int s1, s2;
5
public Son(int x, int y, int z) {
super(x);
s1=y;
s2=z;
}
public void display( ) {
super.display( );
System.out.println(“s1=”+s1+“s2=”+s2);
}
}
public class Test {
public static void main (String args[]) {
Father f=new Son( 5, 6, 7);
f.display( );
}
}
5(下面关于构造方法的说法哪个选项是正确的( )。
A 构造方法不能被重载 B 构造方法不能被继承
C 构造方法可以返回一个对象的引用 D 构造方法可以直接利用对象名调用 6( 关键词用来引用父类中的成员变量和方法, 关键词用来指向当前对象自身。
7(下面代码的输出结果为( )。
class A {
public void prt ( ) {
System.out.println(“1”);
}
public A ( ) {
System.out.println(“A”);
}
}
public class B extends A {
public void prt ( ) {
super.prt ( );
System.out.println(“2”);
}
public B ( ) {
System.out.println(“B”);
}
public static void main(String args[]) {
6
A a=new B( );
a.prt ( );
}
}
8(下面代码的输出结果为( )。
public class Person {
String name;
int age;
String sex;
public Person(String name, int age, String sex) {
this.name=name;
this.age=age;
this.sex=sex;
}
public Person(String name, int age) {
this (name, age, “male”);
}
public Person(String name) {
this (name, 30);
}
public static void main (String args[]) {
Person p1=new Person (“Tom”, 18);
Person p2=new Person (“John”);
System.out.println(p1.name+“-”+p1.age+“-”+p1.sex);
System.out.println(p2.name+“-”+p2.age+“-”+p2.sex);
}
}
9(在子类中重写父类的方法只需要满足相同的方法名和参数列表即可。( )
10(在一个类中可以定义同名的多个方法,它们之间的区别在于参数列表不同,这种叫做方法的 。如果父类中原有的方法不能满足子类的要求,可以在子类中对父类的方法重新编写代码,这叫做方法的 。
11(一个构造方法可以返回一个对象的引用,即返回值类型是引用类型。 ( )
12(下面代码的输出结果为( )。
class OverloadDemo {
void test ( ) {
System.out.println(“No parameters”);
}
7
void test (int a, int b ) {
System.out.println(“a and b: ”+a+“and”+b);
}
void test (double a ) {
System.out.println(“Inside test double a: ”+a);
}
}
public class Overload {
public static void main(String args[]) {
OverloadDemo ob=new OverloadDemo( );
ob.test ( );
ob.test(10,20);
ob.test(123.2);
}
}
13(下面代码的输出结果为( )。
class Graphix {
void calArea( ) {
System.out.println(“求图形面积”);
} }
class Rect extends Graphix {
void calArea( ) {
System.out.println(“求长方形面积”);
} }
class Circle extends Graphix {
void calArea( ) {
System.out.println(“求圆面积”);
} }
public class Test {
public static void main (String args[]) {
Graphix gc=new Rect( );
gc.calArea( );
gc=new Circle( );
gc.calArea( );
}
}
14(在下列关于方法的重载和覆盖的描述中,错误的是( )。 A 方法重载是指在同一个类中允许出现方法参数个数、顺序不同而方法名相同的若干方法
8
B 方法覆盖是指在父类和子类之间出现的方法头相同而方法体不同的多个方法
C 方法重载是在编译时进行选择的
D 方法覆盖是在编译时进行选择的
15(下列代码的输出结果是___________。
public class Oct{
public static void main(String argv[]){
Oct o=new Oct();
o.amethod();
}
public void amethod(){
int oi=012;
System.out.println(oi);
}
16(在下列代码中第___________行将产生编译错误。 1: class Example{
2: String str;
3: public Example(){
4: str="example";
5: }
6: public Example(String s){ 7: str=s;
8: }
9: }
10:class Demo extends Example{ 11:}
12:public class Oct{
13: public void f(){
14: Example ex=new Example("Good");
15: Demo d=new Demo("good"); 16: }
17:}
17(构造方法一般不允许有任何返回值,因此需要在返回类型处标注为void。( )
18(下面代码的输出结果为( )。
class J_Base{
public void mb_method(){
System.out.println("Base");
}
}
9
public class J_Test extends J_Base{
public void mb_method(){
System.out.println("Test");
}
public static void main(String args[]){
Object a=new J_Test();
((J_Base)a).mb_method();
}
}
19. 下面代码的输出结果为( )。
public class InheritTest1{
public static void main(String args[]){
A aa = new A();
B bb = new B();
aa.show();
bb.show();
}
}
public class A{
= 1; int a
double d = 2.0;
void show(){
System.out.println("Class A: " + "\ta=" + a + "\td=" + d);
}
}
public class B extends A{
float a = 3.0f;
String d = "Java program.";
int b = 4;
void show(){
System.out.println("Class A: " + "\ta=" + super.a + "\td=" + super.d);
super.show();
System.out.println("Class B: " + "\ta=" + a + "\td=" + d + "\tb=" + b);
}
}
10
第4章:Java高级特征
1(如果一个方法只有方法的声明,而没有方法的实现,则成为 方法。该方法通过关键字
来定义。
2(类的声明“public class TestJava extends BaseJava implements Runable{ }”中,定义的类名
是 ,其父类是 ,实现了 接口。含有这个类的源程序必须保
存为 (写出包括扩展名的文件名)。 3(下面是类的定义,将程序补充完整。
class A{
String s;
int a=66;
A(String s1){
s=s1;
}
static int geta(){
return a;
}
}
public class {
int x,y;
MyClass(int i, ){
x=i;
y=j;
}
}
4(请在下面程序的划线处填上适当的语句,使程序能正常运行。
class X{
abstract void callme();
void metoo(){
System.out.println("metoo()方法");
}
}
class Y X{
void callme(){
System.out.println("重写的callme()方法");
}
}
5(当你编译和运行下列的代码时,会出现下面选项中的哪种情况( )。
11
public class Pvf {
static boolean Paddy;
public static void main(String[ ] args) {
System.out.println(Paddy);
}}
A 编译时错误 B 编译通过并输出结果false
C 编译通过并输出结果true D 编译通过并输出结果null 6(欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的( )。
A ArrayList myList=new Object(); B ArrayList myList=new List();
C List myList=new ArrayList(); D List myList=new List(); 7(interface Printable {
void print( ) { }; } 上述接口的定义是正确的。 ( )
8(Java语言中同一包(package)中的类不能同名,否则会产生命名冲突。( )
9(在类的定义中使用权限修饰符来保护类的变量和方法,其中类中带有private的成员只能被这个类自身访问。 ( )
10(下列哪个类的声明使得该类不能再派生子类( )。
A static class FooBar { } B abstract class FooBar { }
C public class FooBar { } D final class FooBar { }
11(一个非抽象类要实现某个接口,就必须实现该接口中的所有抽象方法。( )
12(下面代码的输出结果为( )。
public class TestEquals {
public static void main(String args[]) {
String s1=new String(“Hello World!”);
String s2=new String(“Hello World!”);
if(s1= =s2) {
System.out.println(“s1= = s2”);
} else {
System.out.println(“s1!=s2”);
}
if(s1.equals(s2)) {
System.out.println(“s1 is equal to s2”);
}else {
System.out.println(“s1 is not equal to s2”);
}
}
}
13(在类的修饰符中,规定只能被同一包类所使用的修饰符是( )。
A public B 默认 C final D abstract
12
14(Java语言中,定义子类时,使用关键字___________来给出父类名。如果没有指出父类,则该类的默认父类为___________类。
15(接口中所定义的常量具有___________和___________的属性,而其方法具有public和___________
属性。
16(顶层类的访问控制修饰符为___________和___________。
17(下面代码的输出结果为( )。
class J_Class{
static int m_data=0;
}
class J_Test{
public static void main(String args[]){
J_Class a=new J_Class();
J_Class b=new J_Class();
a.m_data=1;
b.m_data=2;
System.out.println(a.m_data);
}
}
18(用整型数10创建一个Integer类的对象,下列语句中能完成上述功能的一个是( )。
A(Integer i=new Integer(10);
B(Integer i=10;
C(int i=10;
D(Integer i=Integer(10);
19(运行下列代码将产生编译错误:
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{
System.out.println(arr[1]);
}
}
第5章:异常处理
1( 如果下列代码在调用oneMethod( )时一定会产生某个异常对象,则哪一条语句肯定不会显示出来
( )。
public void test( ) {
try { oneMethod( ); //调用方法oneMethod( )
13
System.out.println( “condition 1”);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(“condition 2”);
} catch(Exception e) {
System.out.println(“condition 3”);
} finally {
System.out.println(“finally”);
} }
A condition 1 B condition 2 C condition 3 D finally
2(在 Java的异常处理语句try-catch-finally中, 语句后面是可能产生异常的代码,
语句后面是捕获到某种异常对象时进行处理的代码, 语句后面是无论是否捕获到异常
都必须执行的代码。
3(下面代码的输出结果为( )。
public class TestException {
public static void main (String args[]) {
String friends[ ]={“Lisa”, “Bily”};
try {
for(int i=0; i<4; i++) {
System.out.println(friends[i]);
}
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println(“index err”);
}
System.out.println(“This is the end”);
}
}
4(设下列try-catch语句块中的第二个语句s2将引起一个异常,那么以下哪段代码肯定不会被执行( )。
try {
s1;
s2;
s3;
}catch (Exception e1) { }
finally {s4;}
A s1 B s2 C s3 D s4 5(异常处理具体有两种方式: 和 。 6(下面代码的输出结果为( )。
14
public class TestException {
public static void main (String args[]) {
int i=0, num=0;
int s[]={2,4,6};
try {
while(i<4) {
num+=s[i];
i++;
}
System.out.println(“Normal ended.”);
}catch(Exception e) {
System.out.println(“index err”);
}finally {
System.out.println(“this is an end”);
}
}
}
7(在方法中声明将产生的异常抛出使用的关键词是throw 。( )
8(下列关于异常处理的描述中,错误的是( )。 A 程序运行时出现的异常是通过系统默认的异常处理程序进行处理的 B 在程序中可以使用try-catch语句捕捉异常和处理异常事件 C 对于捕获的异常只能在当前方法中处理
D 使用throw语句可将异常抛出到调用当前方法的方法中处理 9(下面代码的输出结果为( )。
public class J_Example{
public static void main(String args[]){
try{
try{
int i=1/0;
}
catch(Exception e){
System.out.print("1");}
finally{
System.out.print("2");}
}
catch(Exception e){
System.out.print("3");
}
15
finally{
System.out.print("4");}
System.out.print("5\n");
}
}
10(下面代码的输出结果为( )。
class ExcepTest{
public static void main(String args[]){
try{
method();
}catch(Exception e){
System.out.println('m');
}
System.out.println('n');
}
static void method(){
try{
wrench();
System.out.println("a");
}catch(ArithmeticException e){
System.out.println("b");
}finally{
System.out.println("c");
}
System.out.println("d");
}
static void wrench(){
throw new NullPointerException();
}
}
第6章:Java输入/输出
1(对于java.io包中的所有I/O类,根据数据流所关联的是数据源还是其他数据流,可分为( )
和( )。
2(下列程序的功能是读取并输出指定文件ReadFile.java的内容。在划线处加入适当代码,使程序能够
正常运行。
1: import java.io.*;
2: public class ReadFile {
16
3: public static void main (String args[] ) { 4: File f=new File(“ReadFile.java”);
5: try {
6: FileReader fr= ; //创建一个从文件f读取数据的文件输入流fr
7: BufferedReader br= ; //创建一个缓存输入流,套接文件流fr
8: String s=br.readLine( ) ; 9: while(s!=null) {
10: ; //在屏幕上显示出字符串str 11: s=br.readLine( );
12: }
13: fr.close( );
14: br.close( );
15: }catch(IOException e) {
16: System.out.println(e.getMessage( )); } 17: }
18: }
3(下列哪条语句可以正确创建出一个BufferedReader数据流( )。
A new BufferedReader(new FileReader(“myFile.txt”));
B new BufferedReader(new FileInputStream(“myFile.txt”));
C new BufferedReader(new DataInputStream(“myFile.txt”));
D new BufferedReader(“myFile.txt”);
4(Java在System类中定义了与系统输入/输出相联系的三个流,他们是( )、( )和( )。
5(在Java的输入/输出中,节点流与过滤流的主要的区别在于处理的流的方向不同。( )
6(InputStream类是输入流类,它是所有字符输入流类的父类。 ( )
7(下列程序实现了从键盘输入字符串,将该字符串存入String类的对象str中,并在屏幕上显示出该字符串。在划线处加入适当代码,使程序能够正常运行。
1: import java.io.*;
2: public class Demo {
3: public static void main (String args[] ) { 4: InputStreamReader isr= ;
5: BufferedReader br=new BufferedReader(isr); 6: try {
7: String str = ; //将br读入的一行字符串存入str
8: ; //在屏幕上显示出字符串str
17
9: }catch(IOException e) {
10: System.out.println(e.getMessage( ));
11: }
12: }
13: }
8(要调用类java.io.InputStream的read或close方法,就必须处理异常,该异常的具体类型是___________。
9(在I/O流FileInputStream、BufferedInputStream、DataInputStream和ByteArrayInputStream中,节点流的个数是___________。
第7章:AWT及AWT事件处理
1(下述哪个方法可以将MenuBar加入到Frame中( )。
A setMenu( ) B setMenuBar( ) C add( ) D addMenuBar( )
2(在java.awt包中, 类是一个容器,可以容纳其他组件和容器,但它却不能独立存在。
下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。) 3(
import java.awt.*;
public class GridLayoutWindow {
public static void main (String args[]) {
Frame f=new Frame(“GridLayout Example”);
f.setLayout(new GridLayout(2,3 ));
Button b1=new Button(“B1”);
Button b2=new Button(“B2”);
Button b3=new Button(“B3”);
Button b4=new Button(“B4”);
Button b5=new Button(“B5”);
Button b6=new Button(“B6”);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.pack( );
f.setVisible(true);
}
}
18
4(编写程序。如图所示,窗口Frame是流式布局管理器,标题为“Test”,当用户每次鼠标单击“Start”按钮时,程序都会在屏幕上的DOS窗口中输出一行字符串“单击成功!”。
5(java.awt包中主要包括三个概念,它们是组件、 和 。 6(下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。)
import java.awt.*;
public class GridLayoutWindow {
public static void main (String args[]) {
Frame f=new Frame(“GridLayout Example”);
f.setLayout(new GridLayout(2,2));
Label b1=new Label(“Label1”);
Button b2=new Button(“Button1”);
Label b3=new Label(“Label2”);
Button b4=new Button(“Button2”);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.pack( );
f.setVisible(true);
}
}
7(下面是一个单击按钮事件响应的,其运行效果为:用户每次鼠标单击“Press Me”按钮时,程序都会在DOS命令窗口中输出一行字符串“a button has been pressed”。请在划线处填写语句,完成此程序,使它能正确执行。
1: import java.awt.*;
2: import ;
3: public class TestActionEvent {
4: public static void main (String args[] ) {
5: Frame f=new Frame(“Test”);
6: Button b=new Button(“Press Me”); //创建一个按钮,标签为Press Me
7: Monitor bh=new Monitor( ); //创建一个监听器类实例bh
19
8: b. ; //为按钮b注册监听器
9: f.pack( );
10: f.setVisible(true);
11: }
12: }
13: class Monitor { //定义监听器类,实现监听器接
口
14: public static void main (String args[]) {
15: public void actionPerformed(ActionEvent e) {
16: System.out.println(“a button has been pressed”);
17: }
18: }
19: }
8(AWT事件处理模型中主要包含三类对象:事件、事件源和事件处理器。( ) 9(下面哪条语句是使用网格布局管理器将一个Frame的实例frm分成1行3列( )。
A frm.setLayout(new GridLayout(1,3)); B frm.setLayout(new GridLayout(3,1));
C frm.setLayout(new GridLayout(3)); D frm.setLayout(new GridLayout(1));
10(默认情况下,Applet使用流式布局管理器(FlowLayout)。 ( ) 11(下面程序的运行结果为( )(注意:本题请画出运行结果,可以文字描述来作辅助说明。)
import java.awt.*;
public class FlowLayoutWindow {
public static void main (String args[]) {
Frame f=new Frame(“FlowLayout Example”);
f.setLayout(new FlowLayout( ));
Button b1=new Button(“OK”);
Button b2=new Button(“OPEN”);
Button b3=new Button(“CLOSE”);
f.add(b1);
f.add(b2);
f.add(b3);
f.setSize(100, 100 );
f.setVisible(true);
} }
12(在AWT中,所有GUI标准组件类的父类是( )。
A Button B List C Component D Container 13(在下列容器中最简单的无边框的又不能移动和缩放的只能包含在另一种容器中的容器是( )。
A Window B Dialog C Frame D Panel 14( 所有事件类的父类是( )。
A ActionEvent B AwtEvent C KeyEvent D MouseEvent
20
15(在AWT中,每种类型的事件都定义了相应的事件处理接口,即___________。委托方式事件处理机制的实现包括______________________和______________________。
16(下面程序的运行结果为( )(注意:本题请画出运行结果。)
import java.awt.*;
public class FrTest{
public static void main(String args[]){
new FrameOut();
}
}
class FrameOut extends Frame{
Button btn1, btn2, btn3;
FrameOut(){
super("Buttons");
setLayout(new FlowLayout());
btn1 = new Button("B1");
add(btn1);
btn2 = new Button("B2");
add(btn2);
btn3 = new Button("B3");
add(btn3);
setSize(300,200);
setVisible(true);
}
}
17(FlowLayout是 和 的默认布局管理器。 第8章:Applet基础编程
1(Applet的生命周期包括Applet的 、 和 几个状态。 2(下列哪个方法与Applet的显示无关( )。
A draw( ) B paint( ) C repaint( ) D update( )
3(在Applet的生命周期中,当打开浏览器窗口时,系统会首先自动调用 方法;而当用
户离开当前窗口时,系统会自动调用 方法。
4(下面是在浏览器中显示“Hello World”的Applet小程序。在划线处加入适当代码,使程序能够正常运行。
1: import java.awt.*;
2: import ;
3: public class HelloWorld extends Applet {
21
4: String text=“Hello World”;
5: pubic void paint (Graphics g) {
6: g. ;
7: }
8: }
5(在Java Applet程序运行时,当浏览器离开含有Applet的网页时被调用的方法是( )。
A stop ( ) B start ( ) C init ( ) D destroy ( )
6(开发一个Applet小程序的第一步是需要引入相关的包和类,该语句为( )。 7(当用户退出浏览器时,Applet从系统中撤出停止自身执行,最后调用的方法是stop( )。 ( )
8(下列
本文档为【第3部分SCJP认证试题-沈阳师范大学】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。