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

📄 scjp试题-scjpmockexam1.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 3 页
字号:
SCJP试题-SCJPMockExam1

Q1 
A method is ... 

1) an implementation of an abstraction. 
2) an attribute defining the property of a particular abstraction. 
3) a category of objects. 
4) an operation defining the behavior for a particular abstraction. 
5) a blueprint for making operations. 

Q2 
An object is ... 

1) what classes are instantiated from. 
2) an instance of a class. 
3) a blueprint for creating concrete realization of abstractions. 
4) a reference to an attribute. 
5) a variable. 

Q3 
Which line contains a constructor in this class definition? 

public class Counter { // (1) 
int current, step; 
public Counter(int startValue, int stepValue) { // (2) 
set(startValue); 
setStepValue(stepValue); 
} 
public int get() { return current; } // (3) 
public void set(int value) { current = value; } // (4) 
public void setStepValue(int stepValue) { step = stepValue; } // (5) 
} 

1) Code marked with (1) is a constructor 
2) Code marked with (2) is a constructor 
3) Code marked with (3) is a constructor 
4) Code marked with (4) is a constructor 
5) Code marked with (5) is a Constructor 

Q4 
Given that Thing is a class, how many objects and reference variables are created by the following code? 

Thing item, stuff; 
item = new Thing(); 
Thing entity = new Thing(); 

1) One object is created 
2) Two objects are created 
3) Three objects are created 
4) One reference variable is created 
5) Two reference variables are created 
6) Three reference variables are created. 




Q5 
An instance member… 

1) is also called a static member 
2) is always a variable 
3) is never a method 
4) belongs to a single instance, not to the class as a whole 
5) always represents an operation 

Q6 
How do objects pass messages in Java? 

1) They pass messages by modifying each other's member variables 
2) They pass messages by modifying the static member variables of each other's classes 
3) They pass messages by calling each other's instance member methods 
4) They pass messages by calling static member methods of each other's classes. 

Q7 
Given the following code, which statements are true? 

class A { 
int value1; 
} 
class B extends A { 
int value2; 
} 

1) Class A extends class B. 
2) Class B is the superclass of class A. 
3) Class A inherits from class B. 
4) Class B is a subclass of class A. 
5) Objects of class A have a member variable named value2. 

Q8 
If this source code is contained in a file called SmallProg.java, what command should be used to compile it using the JDK? 

public class SmallProg { 
public static void main(String args[]) { System.out.println("Good luck!"); } 
} 

1) java SmallProg 
2) avac SmallProg 
3) java SmallProg.java 
4) javac SmallProg.java 
5) java SmallProg main 

Q9 
Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation? 

public class Q6db8 { 
int a; 
int b = 0; 
static int c; 
public void m() { 
int d; 
int e = 0; 
// Position 1 
} 
} 

1) a++; 
2) b++; 
3) c++; 
4) d++; 
5) e++; 

Q10 
Which statements are true concerning the effect of the >> and >>> operators? 

1) For non-negative values of the left operand, the >> and >>> operators will have the same effect. 
2) The result of (-1 >> 1) is 0. 
3) The result of (-1 >>> 1) is -1. 
4) The value returned by >>> will never be negative as long as the value of the right operand is equal to or greater than 1. 
5) When using the >> operator, the leftmost bit of the bit representation of the resulting value will always be the same bit value as the leftmost bit of the bit representation of the left operand. 

Q11 
What is wrong with the following code? 

class MyException extends Exception {} 

public class Qb4ab { 
public void foo() { 
try { 
bar(); 
} finally { 
baz(); 
} catch (MyException e) {} 
} 
public void bar() throws MyException { 
throw new MyException(); 
} 
public void baz() throws RuntimeException { 
throw new RuntimeException(); 
} 
} 

1) Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause. 
2) A try block cannot be followed by both a catch and a finally block. 
3) An empty catch block is not allowed. 
4) A catch block cannot follow a finally block. 
5) A finally block must always follow one or more catch blocks. 




Q12 
What will be written to the standard output when the following program is run? 

public class Qd803 { 
public static void main(String args[]) { 
String word = "restructure"; 
System.out.println(word.substring(2, 3)); 
} 
} 

1) est 
2) es 
3) str 
4) st 
5) s 

Q13 
Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work? 

CODE BLOCK A: 
Runnable r = new Runnable() { 
public void run() { 
Work.doIt(); 
} 
}; 
Thread t = new Thread(r); 
t.start(); 

CODE BLOCK B: 
Thread t = new Thread() { 
public void start() { 
Work.doIt(); 
} 
}; 
t.start(); 

CODE BLOCK C: 
Runnable r = new Runnable() { 
public void run() { 
Work.doIt(); 
} 
}; 
r.start(); 

CODE BLOCK D: 
Thread t = new Thread(new Work()); 
t.start(); 

CODE BLOCK E: 
Runnable t = new Runnable() { 
public void run() { 
Work.doIt(); 
} 
}; 
t.run(); 

1) Code block A. 
2) Code block B. 
3) Code block C. 
4) Code block D. 
5) Code block E. 

Q14 
Write a line of code that declares a variable named layout of type LayoutManager and initializes it with a new object, which when used with a container can lay out components in a rectangular grid of equal-sized rectangles, 3 components wide and 2 components high. 

Q15 
public class Q275d { 
static int a; 
int b; 
public Q275d() { 
int c; 
c = a; 
a++; 
b += c; 
} 
public static void main(String args[]) { 
new Q275d(); 
} 
} 

1) The code will fail to compile, since the constructor is trying to access static members. 
2) The code will fail to compile, since the constructor is trying to use static member variable a before it has been initialized. 
3) The code will fail to compile, since the constructor is trying to use member variable b before it has been initialized. 
4) The code will fail to compile, since the constructor is trying to use local variable c before it has been initialized. 
5) The code will compile and run without any problems. 




Q16 
What will be written to the standard output when the following program is run? 

public class Q63e3 { 
public static void main(String args[]) { 
System.out.println(9 ^ 2); 
} 
} 

1) 81 
2) 7 
3) 11 
4) 0 
5) false 

Q17 
Which statements are true concerning the default layout manager for containers in the java.awt package? 

1) Objects instantiated from Panel do not have a default layout manager. 
2) Objects instantiated from Panel have FlowLayout as default layout manager. 
3) Objects instantiated from Applet have BorderLayout as default layout manager. 
4) Objects instantiated from Dialog have BorderLayout as default layout manager. 
5) Objects instantiated from Window have the same default layout manager as instances of Applet. 

Q18 
Which declarations will allow a class to be started as a standalone program? 

1) public void main(String args[]) 
2) public void static main(String args[]) 
3) public static main(String[] argv) 
4) final public static void main(String [] array) 
5) public static void main(String args[]) 

Q19 
Under which circumstances will a thread stop? 

1) The method waitforId() in class MediaTracker is called. 
2) The run() method that the thread is executing ends. 
3) The call to the start() method of the Thread object returns. 
4) The suspend() method is called on the Thread object. 
5) The wait() method is called on the Thread object. 

Q20 
When creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable? 

1) Collection 
2) Set 
3) SortedSet 
4) Map 

Q21 
What does the value returned by the method getID() found in class java.awt.AWTEvent uniquely identify? 

1) The particular event instance. 
2) The source of the event. 
3) The set of events that were triggered by the same action. 
4) The type of event. 
5) The type of component from which the event originated. 

Q22 
What will be written to the standard output when the following program is run? 

class Base { 
int i; 
Base() { 
add(1); 
} 
void add(int v) { 
i += v; 
} 
void print() { 
System.out.println(i); 
} 
} 
class Extension extends Base { 
Extension() { 
add(2); 
} 
void add(int v) { 
i += v*2; 
} 
} 
public class Qd073 { 
public static void main(String args[]) { 
bogo(new Extension()); 
} 
static void bogo(Base b) { 
b.add(8); 
b.print(); 
} 
} 

1) 9 
2) 18 
3) 20 
4) 21 
5) 22 




Q23 
Which lines of code are valid declarations of a native method when occurring within the declaration of the following class? 

public class Qf575 { 
// insert declaration of a native method here 
} 

1) native public void setTemperature(int kelvin); 
2) private native void setTemperature(int kelvin); 
3) protected int native getTemperature(); 
4) public abstract native void setTemperature(int kelvin); 
5) native int setTemperature(int kelvin) {} 

Q24 
How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components? 

1) It affects which grid cell the components end up in. 
2) It affects how the extra vertical space is distributed. 
3) It affects the alignment of each component. 
4) It affects whether the components completely fill their allotted display area vertically. 

Q25 
Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run? 

public class Q4a39 { 
int a = 1; 
int b = 1; 
int c = 1; 
class Inner { 
int a = 2; 
int get() { 
int c = 3; 
// insert statement here 
return c; 
} 
} 
Q4a39() { 
Inner i = new Inner(); 
System.out.println(i.get()); 
} 
public static void main(String args[]) { 
new Q4a39(); 
} 
} 

1) c = b; 
2) c = this.a; 

⌨️ 快捷键说明

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