java自测题三

Which statement is true about the grid bag layout manager?
   A. The number of rows and columns is fixed when the container is created.
   B. The number of rows and columns is fixed when the GridBagLayout object is
created.
   C. If a component has a fill value of BOTH, then as the container change size, the
component is resized.
D. Every component must carry a non-zero weightx and weighty value when it is added
to the container
   E. If a row has a weighty value that is non-zero, then as the container changes
height, the row changes height.


请选择: A B C D E
答案:C

Consider the following code: What will be printed?
public class Arg{
String [] MyArg;
public static void main(String arg[]){
MyArg[] = arg[];
}

public void amethod(){
System.out.println(arg[1]);
}
}
A. null
B. 0
C. Nothing will be printed. Compilation error.
D. Compiles just fine, but a RuntimeException will be thrown.

请选择: A B C D
答案:C

Consider the code fragment below:
outer: for(int i = 0; i < 2; i++){
inner: for(int j = 0; j < 2; j++){
if(j==1)
break outer;
System.out.println("i = " + i ", j = " + j);
}
}
Which of the following will be printed to standard output?
A. i = 0, j = 0
B. i = 1, j = 0
C. i = 2, j = 0
D. i = 0, j = 1
E. i = 1, j = 1
F. i = 2, j = 1

请选择: A B C D E F
答案:A

What access control keyword should you use to enable other classes to access a
method freely within its package, but to restrict classes outside of the package
from accessing that method? Select all valid answers.
a. private
b. public
c. protected
d. Do not supply an access control keyword (friendly).

请选择: A B C D
答案:D


1) interface Foo{
2) int k=0;
3) }
4) public class Test implements Foo{
5) public static void main(String args[]){
6) int i;
7) Test test =new Test();
8) i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12) }

What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.



What will happen when you attempt to compile and run this code?
class Test{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Test{
public static void main(String argv[]){
Abs a=new Abs();
a.amethod();
}

public void myfunc(){
System.out.println("My func");
}

public void amethod(){
myfunc();
}
}

Select the one right answer.

A.The code will compile and run,printing out the words"My Func"
B.The compiler will complain that the Test class is not declared as abstract methods.
C.The code will compile but complain at run time that Test class has non
abstract methods.
D.The compiler will complain that the method myfunc int the base class has no
body,nobody at all to looove it


请选择: A B C D
答案:B
点评:当类中存在一个以上的抽象方法时,该类必须被声明为抽象类,否则会发生编译错误。在本例中
,由于基类Test存在一个抽象的方法myfunc(),而该基类没有被声明为抽象类,所以在编译时产生
错误.


What will happen when you attempt to compile and run this code?
class Test{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Test{
public static void main(String argv[]){
Abs a=new Abs();
a.amethod();
}

public void myfunc(){
System.out.println("My func");
}

public void amethod(){
myfunc();
}
}

Select the one right answer.

A.The code will compile and run,printing out the words"My Func"
B.The compiler will complain that the Test class is not declared as abstract methods.
C.The code will compile but complain at run time that Test class has non
abstract methods.
D.The compiler will complain that the method myfunc int the base class has no
body,nobody at all to looove it


请选择: A B C D
答案:B
点评:当类中存在一个以上的抽象方法时,该类必须被声明为抽象类,否则会发生编译错误。在本例中
,由于基类Test存在一个抽象的方法myfunc(),而该基类没有被声明为抽象类,所以在编译时产生
错误.

String foo="blue";
boolean[] bar=new boolean[1];
if(bar[0]){
foo="green";
}
what is the value of foo?
A."" B.null C.blue D.green


请选择: A B C D
答案:C


Given the following class:
  public class Sample{
  long length;
  public Sample(long l){ length = l; }
  public static void main(String arg[]){
  Sample s1, s2, s3;
  s1 = new Sample(21L);
  s2 = new Sample(21L);
  s3 = s2;
  long m = 21L;
  }
  }

Which expression returns true?
  A. s1 == s2;
  B. s2 == s3;
  C. m == s1;
  D. s1.equals(m).


请选择: A B C D
答案:B
点评:==操作符两边的操作数必须是同一类型的(可以是父子类之间)才能编译通过。

A public member vairable called MAX_LENGTH which is int type, the value of the variable
remains constant value 100. Use a short statement to define the variable.
  A. public int MAX_LENGTH=100;
  B. final int MAX_LENGTH=100;
  C. final public int MAX_LENGTH=100;
  D. public final int MAX_LENGTH=100.


请选择: A B C D
答案:D
点评: Java中共有变量使用public定义,常量变量使用final,另外注意的是修饰符的顺序,一个最完整的修饰是public static final int varial_a=100;这个顺序不能错,这和c++中也是不同的。而答案c恰恰错在修饰符的顺序上。

What can you place first in this file?
//What can you put here?
public class Apa{}
A. class a implements Apa
B. protected class B {}
C. private abstract class{}
D. import java.awt.*;
E. package dum.util;
F. private int super = 1000;

请选择: A B C D E
答案:A D E


import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);
}
public X(){
setLayout(new BorderLayout());
Panel p=new Panel();
add(p,BorderLayout.NORTH);
Button b=new Button("North");
p.add(b);
Button b1=new Button("South");
add(b1,BorderLayout.SOUTH);
}
which two are true?
A. The button labeled "North" and "South" will have the same width
B. The button labeled "North" and "South" will have the same height
C. The height of the button labeled "North" can vary if the Frame is resized
D. The height of the button labeled "South" can vary if the Frame is resized
E. The width of the button labeled "North" is constant even if the Frame is
resized
F. The width of the button labeled "South" is constant even if the Frame is
resized


请选择: A B C D E F
答案:B E
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值