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

📄 scjp试题-scjpmockexam2.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 5 页
字号:
Given the following class

public class Ombersley{
public static void main(String argv[]){
boolean b1 = true;
if((b1 ==true) || place(true)){
System.out.println("Hello Crowle");
}
}

public static boolean place(b public static boolean place(boolean location){
if(location==true){
System.out.println("Borcetshire");
}
System.out.println("Powick");
return true;
turn true;
}
}
What will happen when you attempt to compile and run it?


1) Compile time error 
2) Output of "Hello Crowle" 
3) Output of Hello Crowle followed by Borcetshire and Powick 
4) No output

Answer to Question 27) 







Question 28)
You are given a class hierarchy with an instance of the class Dog. The class Dog is a child of mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string "move". The class mammal overrides this method and prints out the string "walks". The class Dog overrides this method and prints out the string "walks on paws". Given an instance of the class Dog,. how can you access the ancestor method move in Vertebrate so it prints out the string "move";

1) d.super().super().move(); 
2) d.parent().parent().move(); 
3) d.move(); 
4) none of the above;

Answer to Question 28) 


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

Question 29)
Which of the following most closely describes the process of overriding?

1) A class with the same name replaces the functionality of a class defined earlier in the hierarchy 
2) A method with the same name completely replaces the functionality of a method earlier in the hierarchy 
3) A method with the same name but different parameters gives multiple uses for the same method name 
4) A class is prevented from accessing methods in its immediate ancestor

Answer to Question 29) 


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

Question 30)
Which of the following statements are true?

1) The % is used to calculate a percentage thus: 10 % 20=50 
2) The / operator is used to divide one value by another 
3) The # symbol may not be used as the first character of a variable 
4) The $ symbol may not be used as the first character of a variable

Answer to Question 30) 


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

Question 31)
Which of the following statements are true?

1) The default layout manager for an Applet is FlowLayout 
2) The default layout manager for a Frame is FlowLayout 
3) A layout manager must be assigned to an Applet before the setSize method is called 
4) The FlowLayout manager attempts to honor the preferred size of any components

Answer to Question 31)


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

Question 32)
Which of the following statements are true about a variable created with the static modifier?

1) Once assigned the value of a static variable may not be altered
2) A static variable created in a method will keep the same value between calls
3) Only one instance of a static variable will exist for any amount of class instances
4) The static modifier can only be applied to a primitive value

Answer to Question 32)


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

Question 33)
Which of the following statements are true?

1) Java uses a system called UTF for I/O to support international character sets
2) The RandomAccessFile is the most suitable class for supporting international character sets
3) An instance of FileInputStream may not be chained to an instance of FileOutputStream 
4) File I/O activities requires use of Exception handling

Answer to Question 33)


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

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

import java.io.*;
class ExBase{
abstract public void martley(){ 
}

}

public class MyEx extends ExBase{
public static void main(String argv[]){
DataInputStream fi = new DataInputStream(System.in);
try{
fi.readChar();
}catch(IOException e){
System.exit(0);
}
finally {System.out.println("Doing finally");}
}
} 
1) Compile time error
2) It will run, wait for a key press and then exit
3) It will run, wait for a keypress, print "Doing finally" then exit
4) At run and immediately exit

Answer to Question 34)







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

public class Borley extends Thread{
public static void main(String argv[]){
Borley b = new Borley();
b.start();
}
public void run(){ 
System.out.println("Running");
}
}
1) Compilation and run but no output 
2) Compilation and run with the output "Running" 
3) Compile time error with complaint of no Thread target 
4) Compile time error with complaint of no access to Thread package

Answer to Question 35)


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

Question 36)
Assuming any exception handling has been set up, which of the following will create an instance of the RandomAccessFile class

1) RandomAccessFile raf=new RandomAccessFile("myfile.txt","rw");
2) RandomAccessFile raf=new RandomAccessFile( new DataInputStream());
3) RandomAccessFile raf=new RandomAccessFile("myfile.txt");
4) RandomAccessFile raf=new RandomAccessFile( new File("myfile.txt"));

Answer to Question 36)


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

Question 37)
Given the following class definition

public class Upton{
public static void main(String argv[]){ 
}
public void amethod(int i){}
//Here
}
Which of the following would be legal to place after the comment //Here ?
1) public int amethod(int z){} 
2) public int amethod(int i,int j){return 99;} 
3) protected void amethod(long l){ } 
4) private void anothermethod(){}

Answer to Question 37)


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

Question 38)
Which of the following statements are true?

1) Code must be written if the programmer wants a frame to close on selecting the system close menu 
2) The default layout for a Frame is the BorderLayout Manager
3) The layout manager for a Frame cannot be changed once it has been assigned
4) The GridBagLayout manager makes extensive use of the the GridBagConstraints class.

Answer to Question 38)


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

Question 39)
Given the following class definition

public class Droitwich{
class one{
private class two{
public void main(){
System.out.println("two");
}
}
}
}
Which of the following statements are true


1) The code will not compile because the classes are nested to more than one level
2) The code will not compile because class two is marked as private
3) The code will compile and output the string two at runtime
4) The code will compile without error

Answer to Question 39)


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

Question 40)
Given the following code

class Base{
static int oak=99;
}

public class Doverdale extends Base{
public static void main(String argv[]){
Doverdale d = new Doverdale();
d.amethod();
}
public void amethod(){
//Here
} 
}
Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak?

1) super.oak=1;
2) oak=33;
3) Base.oak=22;
4) oak=50.1;

Answer to Question 40)







Question 41)
You are creating an application that has a form with a text entry field used to enter a persons age. Which of the following is appropriate for capturing this information.


1) Use the Text field of a TextField and parse the result using Integer
2) Use the getInteger method of the TextField
3) Use the getText method of a TextBox and parse the result using the getInt method of Integer class
4) Use the getText method of a TextField and use the parseInt method of the Integer class

Answer to Question 41)


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

Question 42)
Given the following declaration


Integer i=new Integer(99);


How can you now set the value of i to 10?


1) i=10;
2) i.setValue(10);
3) i.parseInt(10);
4) none of the above





Answer to Question 42)


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

Question 43)
Which of the following statements are true

1) constructors cannot be overloaded
2) constructors cannot be overridden
3) a constructor can return a primitive or an object reference
4) constructor code executes from the current class up the hierarchy to the ancestor class



Answer to Question 43)


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

Question 44)
Given a reference called

t

to to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.

1) t.yield();
2) yield();
3) yield(100); //Or some other suitable amount in milliseconds
4) yield(t);

Answer to Question 44)


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

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

public class Sandys{
private int court;
public static void main(String argv[]){
Sandys s = new Sandys(99);
System.out.println(s.court);
}
Sandys(int ballcount){
court=ballcount;
}
}

1) Compile time error, the variable court is defined as private
2) Compile time error, s is not initialized when the System.out method is called
3) Compilation and execution with no output
4) Compilation and run with an output of 99

Answer to Question 45)







Question 46)

Which of the following statements are true?

1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method must have the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types



Answer to Question 46)


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

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

class Base{
Base(){
System.out.println("Base");
}
}

public class Checket extends Base{
public static void main(String argv[]){
Checket c = new Checket();
super();
}

Checket(){
System.out.println("Checket"); 
} 
}
1) Compile time error
2) Checket followed by Base
3) Base followed by Checket
4) runtime error

Answer to Question 47)


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

Question 48)

⌨️ 快捷键说明

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