JAVA认证格林模拟试题二(上)
来源:优易学  2011-11-28 15:02:00   【优易学:中国教育考试门户网】   资料下载   IT书店

question 1)

what will happen when you attempt to compile and run this code

abstract class base{
abstract public void myfunc();
public void another(){
system.out.println("another method");
}
}

public class abs extends base{
public static void main(string argv[]){
abs a = new abs();
a.amethod();
}
public void myfunc(){
system.out.println("my func");
}
public void amethod(){
myfunc();
}
}

1) the code will compile and run, printing out the words "my func"
2) the compiler will complain that the base class has non abstract methods
3) the code will compile but complain at run time that the base class has non abstract methods
4) the compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it


question 2)
what will happen when you attempt to compile and run this code?

public class mymain{
public static void main(string argv){
system.out.println("hello cruel world");
}
}

1) the compiler will complain that main is a reserved word and cannot be used for a class
2) the code will compile and when run will print out "hello cruel world"
3) the code will compile but will complain at run time that no constructor is defined
4) the code will compile but will complain at run time that main is not correctly defined


question 3)

which of the following are java modifiers?

1) public
2) private
3) friendly
4) transient
5) vagrant

question 4)

what will happen when you attempt to compile and run this code?

class base{
abstract public void myfunc();
public void another(){
system.out.println("another method");
}
}

public class abs extends base{
public static void main(string argv[]){
abs a = new abs();
a.amethod();
}

public void myfunc(){
system.out.println("my func");
}

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

1) the code will compile and run, printing out the words "my func"
2) the compiler will complain that the base class is not declared as abstract.
3) the code will compile but complain at run time that the base class has non abstract methods
4) the compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it


question 5)

why might you define a method as native?

1) to get to access hardware that java does not know about
2) to define a new data type such as an unsigned integer
3) to write optimised code for performance in a language such as c/c++
4) to overcome the limitation of the private scope of a method


question 6)

what will happen when you attempt to compile and run this code?

class base{
public final void amethod(){
system.out.println("amethod");
}
}

public class fin extends base{
public static void main(string argv[]){
base b = new base();
b.amethod();
}
}

1) compile time error indicating that a class with any final methods must be declared final itself
2) compile time error indicating that you cannot inherit from a class with final methods
3) run time error indicating that base is not defined as final
4) success in compilation and output of "amethod" at run time.

question 7)

what will happen when you attempt to compile and run this code?

public class mod{
public static void main(string argv[]){
}
public static native void amethod();

}

1) error at compilation: native method cannot be static
2) error at compilation native method must return value
3) compilation but error at run time unless you have made code containing native amethod available
4) compilation and execution without error


question 8)

what will happen when you attempt to compile and run this code?

private class base{}
public class vis{
transient int ival;
public static void main(string elephant[]){
}
}

1)compile time error: base cannot be private
2)compile time error indicating that an integer cannot be transient
3)compile time error transient not a data type
4)compile time error malformed main method

question 9)

what happens when you attempt to compile and run these two files in the same directory?

//file p1.java
package mypackage;
class p1{
void afancymethod(){
system.out.println("what a fancy method");
}
}
//file p2.java
public class p2 extends p1{
public static void main(string argv[]){
p2 p2 = new p2();
p2.afancymethod();
}
}

1) both compile and p2 outputs "what a fancy method" when run
2) neither will compile
3) both compile but p2 has an error at run time
4) p1 compiles cleanly but p2 has an error at compile time

question 10)

you want to find out the value of the last element of an array. you write the following code. what will happen when you compile and run it.?

public class myar{
public static void main(string argv[]){
int[] i = new int[5];
system.out.println(i[5]);
}
}

1) an error at compile time
2) an error at run time
3) the value 0 will be output
4) the string "null" will be output


 

[1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训