SCJP试题-SCJPMockExam3

来源:java认证发布时间:2012-11-12 12:48:16java认证视频

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

Answer to Question 1


--------------------------------------------------------------------------------

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

Answer to Question 2


--------------------------------------------------------------------------------

Question 3)
Which of the following are Java modifiers?

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

Answer to Question 3


--------------------------------------------------------------------------------

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

Answer to Question 4





--------------------------------------------------------------------------------

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

Answer to Question 5





--------------------------------------------------------------------------------

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.

Answer to Question 6


--------------------------------------------------------------------------------

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

Answer to Question 7





--------------------------------------------------------------------------------

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

Answer to Question 8





--------------------------------------------------------------------------------

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{
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

Answer to Question 9


--------------------------------------------------------------------------------

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

Answer to Question 10

上一页123456下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答