2024年4月2日发(作者:)
一.Which two demonstrate an “is a” relationship? (Choose Two)
A. public interface Person { }//语法错了
public class Employee extends Person { }
B. public interface Shape { }//语法错了
public class Employee extends Sha pe { }
C. public interface Color { }//语法错了
public class Employee extends Color { }
D. public class Species { }
public class Animal{private Species species;}
E. interface Component { }
Class Container implements Component (
Private Component[ ] children;
二.which statement is true?
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement mutiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
(不能)
E. Construction of an instance of a static inner class requires an instance of the
encloing outer class
构造一个静态的内部类对象需要构造包含它的外部类的对象
三. Given:
1. package foo;
2.
3. public class Outer (
4. public static class Inner (
5. )
6. )
Which statement is true?
A. An instance of the Inner class can be constructed with “new ()”
B. An instance of the inner class cannot be constructed outside of package foo
他们都是public的,只要在外部import就行
C. An instance of the inner class can only be constructed from within the outer
class
D. From within the package bar, an instance of the inner class can be constructed
with “new inner()”
四.Exhibit(展览、陈列):
1 public class enclosinggone{
2 public class insideone{}
3 }
4 public class inertest{
5 public static void main (String[] args){
6 enclosingone eo = new enclosingone();
7 //insert code here
8 }
}
Which statement at line 7 constructs an instance of the inner class?
A. InsideOne ei = InsideOne(); 写程序试出来
B. One ei = InsideOne();
C InsideOne ei = InsideOne();
ingOne InsideOne ei = InsideOne();
五.
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.
六.
//point X
public class Foo{
public static void main(String[] args){
PrintWriter out=new PrintWriter(new
StreamWriter(),true);
n("Hello");
}
}
which statement at point X on line 1 allows this code to compile and run?
在point X这个位置要填入什么代码才能使程序运行
riter e riter
StreamWriter e StreamWriter
statement is needed
本来两个都要import,但是后者OutputStreamWriter指定了包结构
StreamWriter
七. what is reserved words in java? 保留字而非关键字
A. run
B. default
C. implement
D. import
八. which three are valid declaraction of a float?
(float作为整数是可以的,其余几个都是double)
A. float foo=-1;
B. float foo=1.0;
C. float foo=42e1;
D. float foo=2.02f;
E. float foo=3.03d;
F. float foo=0x0123;
九. Given:
8. int index = 1;
9. boolean[] test = new boolean[3]; (数组作为对象缺省初始化为false)
10. boolean foo= test [index];
What is the result?
A. foo has the value of 0
B. foo has the value of null
C. foo has the value of true
D. foo has the value of false
E. an exception is thrown
F. the code will not compile
十. Given:
1. public class test(
2. public static void main(String[]args){
3. String foo = args [1];
4. String foo = args [2];
5. String foo = args [3];
6. }
7. }
And the command line invocation:
Java Test
What is the result?
A. baz has the value of “”
B. baz has the value of null
C. baz has the value of “red”
D. baz has the value of “blue”
E. bax has the value of “green”
F. the code does not compile
G. the program throws an exception
(此题题目出错了,重复定义了变量foo,如果没有重复的话,应选G,因为只传
递了0-2三个数组元素,而题目中需要访问args [3],所以会抛出数组越界异常)
十一.
int index=1;
int foo[]=new int[3];
int bar=foo[index]; //bar=0
int baz=bar+index; //baz=1
what is the result?
A. baz has a value of 0
B. baz has value of 1
C. baz has value of 2
D. an exception is thrown
E. the code will not compile
十二.
1)public class Foo{
2) public static void main(String args[]){
3) String s;
4) n("s="+s);
5) }
6) }
what is the result?
A. The code compiles and “s=” is printed.
B. The code compiles and “s=null” is printed.
C. The code does not compile because string s is not initialized.
D. The code does not compile because string s cannot be referenced.
E. The code compiles, but a NullPointerException is thrown when toString is
called.
十三. Which will declare a method that forces a subclass to implement it?
(谁声明了一个方法,子类必须实现它)
发布者:admin,转转请注明出处:http://www.yc00.com/news/1712043191a1995640.html
评论列表(0条)