⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scjp试题-scjpmockexam3.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 4 页
字号:
4) An interface that ensures that implementing classes cannot contain duplicate keys 

Answer to Question 20)







Question 21)
How does the set collection deal with duplicate elements?

1) An exception is thrown if you attempt to add an element with a duplicate value
2) The add method returns false if you attempt to add an element with a duplicate value
3) A set may contain elements that return duplicate values from a call to the equals method
4) Duplicate values will cause an error at compile time

Answer to Question 21)


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

Question 22)
What can cause a thread to stop executing?

1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method of the Thread class


Answer to Question 22)


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

Question 23)
For a class defined inside a method, what rule governs access to the variables of the enclosing method?

1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
4) The class can only access final variables

Answer to Question 23)


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

Question 24)

Under what circumstances might you use the yield method of the Thread class

1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run

Answer to Question 24)


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

Question 25)
What will happen when you attempt to compile and run the following code

public class Hope{
public static void main(String argv[]){
Hope h = new Hope();
}

protected Hope(){
for(int i =0; i <10; i ++){
System.out.println(i);
}
}
}

1) Compilation error: Constructors cannot be declared protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9

Answer to Question 25)


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

Question 26)
What will happen when you attempt to compile and run the following code

public class MySwitch{
public static void main(String argv[]){
MySwitch ms= new MySwitch();
ms.amethod();
}


public void amethod(){
int k=10; 
switch(k){ 
default: //Put the default at the bottom, not here
System.out.println("This is the default output"); 
break; 
case 10: 
System.out.println("ten");
case 20: 
System.out.println("twenty"); 
break; 
}
}
}
1) None of these options
2) Compile time error target of switch must be an integral type
3) Compile and run with output "This is the default output"
4) Compile and run with output of the single line "ten"

Answer to Question 26)


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

Question 27)
Which of the following is the correct syntax for suggesting that the JVM performs garbage collection

1) System.free();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();

Answer to Question 27)


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

Question 28)

What will happen when you attempt to compile and run the following code

public class As{
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(String argv[]){
As a = new As();
a.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b); 
}
}

1) Compilation succeeds and at run time an output of 0 and false
2) Compilation succeeds and at run time an output of 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value

Answer to Question 28)


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

Question 29)

What will happen when you attempt to compile and run the following code with the command line "hello there"

public class Arg{
String[] MyArg;
public static void main(String argv[]){
MyArg=argv;
}

public void amethod(){
System.out.println(argv[1]);
}
}
1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above

Answer to Question 29)


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

Question 30)
What will happen when you attempt to compile and run the following code

public class StrEq{
public static void main(String argv[]){
StrEq s = new StrEq();
}
private StrEq(){
String s = "Marcus";
String s2 = new String("Marcus");
if(s == s2){
System.out.println("we have a match");
}else{
System.out.println("Not equal");
}
}
}
1) Compile time error caused by private constructor
2) Output of "we have a match"
3) Output of "Not equal"
4) Compile time error by attempting to compare strings using ==

Answer to Question 30)







Question 31)
1) What will happen when you attempt to compile and run the following code

import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}

public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e = new ExcepDemo();
}

public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din = new DataInputStream(System.in);
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
}catch(IOException ioe) {}

}
}

1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output of "Pausing" and "Continuing" after a key is hit

Answer to Question 31)


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

Question 32)

What will happen when you attempt to compile and run this program

public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
1) Compile and run with output of "Outer"
2) Compile and run with output of "Inner"
3) Compile time error because Inner is declared as private
4) Compile time error because of the line creating the instance of Inner

Answer to Question to 32


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

Question 33)
What will happen when you attempt to compile and run this code

//Demonstration of event handling

import java.awt.event.*;
import java.awt.*;
public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}//End of windowClosing
public void MyWc(){
setSize(300,300);
setVisible(true);
}
}//End of class
1) Error at compile time
2) Visible Frame created that that can be closed
3) Compilation but no output at run time
4) Error at compile time because of comment before import statements

Answer to Question 33)


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

Question 34)
Which option most fully describes will happen when you attempt to compile and run the following code

public class MyAr{
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
static int i;
System.out.println(i);
}
}
1) Compilation and output of the value 0
2) Compile time error because i has not been initialized
3) Compilation and output of null
4) Compile time error

Answer to Question 34)


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

Question 35)
Which of the following will compile correctly

1) short myshort = 99S;
2) String name = 'Excellent tutorial Mr Green';
3) char c = 17c;
4)int z = 015;

Answer to Question 35)


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

Question 36)
Which of the following are Java key words
1)double
2)Switch
3)then
4)instanceof

Answer to Question 36)


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

Question 37)

What will be output by the following line?

System.out.println(Math.floor(-2.1));
1) -2
2) 2.0
3) -3
4) -3.0

Answer to Question 37)


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

Question 38)
Given the following main method in a class called Cycle and a command line of

java Cycle one two
what will be output?

public static void main(String bicycle[]){
System.out.println(bicycle[0]);
}
1) None of these options
2) cycle
3) one
4) two

Answer to Question 38)


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

Question 39)
Which of the following statements are true?

1) At the root of the collection hierarchy is a class called Collection
2) The collection interface contains a method called enumerator
3) The interator method returns an instance of the Vector class
4) The set interface is designed for unique elements

Answer to Question 39)


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

Question 40)
Which of the following statements are correct?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -