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

📄 scjp试题-scjpmockexam2.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 5 页
字号:
Which of the following statements are true?

1) Static methods cannot be overriden to be non static
2) Static methods cannot be declared as private
3) Private methods cannot be overloaded
4) An overloaded method cannot throw exceptions not checked in the base class

Answer to Question 48)


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

Question 49)
Which of the following statements are true?

1) The automatic garbage collection of the JVM prevents programs from ever running out of memory
2) A program can suggest that garbage collection be performed but not force it
3) Garbage collection is platform independent
4) An object becomes eligible for garbage collection when all references denoting it are set to null.

Answer to Question 49)


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

Question 50)
Given the following code

public class Sytch{

int x=2000;

public static void main(String argv[]){

System.out.println("Ms "+argv[1]+"Please pay $"+x);

}

}

What will happen if you attempt to compile and run this code with the command line

java Sytch Jones Diggle
1) Compilation and output of Ms Diggle Please pay $2000
2) Compile time error
3) Compilation and output of Ms Jones Please pay $2000
4) Compilation but runtime error

Answer to Question 50)


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

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

class Base{
protected int i = 99;
}
public class Ab{
private int i=1;
public static void main(String argv[]){
Ab a = new Ab();
a.hallow();
}

abstract void hallow(){
System.out.println("Claines "+i);
}

}
1) Compile time error
2) Compilation and output of Claines 99
3) Compilation and output of Claines 1
4) Compilation and not output at runtime

Answer to Question 51)


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

Question 52)
You have been asked to create a scheduling system for a hotel and catering organsiation.

You have been given the following information and asked to create a set of classes to represent it.

On the catering side of the organsiation they have

Head Chefs 
Chefs 
Apprentice Chefs

The system needs to store an employeeid, salary and the holiday entitlement

How would you best represent this information in Javae been given the following information and asked to create a set of classes to represent it.

On the catering side of the organsiation they have

Head Chefs 
Chefs 
Apprentice Chefs

The system needs to store an employeeid, salary and the holiday entitlement

How would you best represent this information in Java

1) Create classes for Head Chef, Chef, Apprentice Chef and store the other values in fields 
2) Create an employee class and derive sub classes for Head Chef, Chef, Apprentice Chef and store the other values in fields. 
3) Create and employee class with fields for Job title and fields for the other values. 
4) Create classes for all of the items mentioned and create a container class to represent employees

Answer to Question 52)







Question 53)
You need to read in the lines of a large text file containing tens of megabytes of data. Which of the following would be most suitable for reading in such a file

1) new FileInputStream("file.name") 
2) new InputStreamReader(new FileInputStream("file.name")) 
3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name")));
4) new RandomAccessFile raf=new RandomAccessFile("myfile.txt","+rw");

Answer to Question 53)


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

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

public class Inc{
public static void main(String argv[]){
Inc inc = new Inc();
int i =0; 
inc.fermin(i);
i = i++;
System.out.println(i);
}
void fermin(int i){
i++;
}
}
1) Compile time error
2) Output of 2
3) Output of 1
4) Output of 0

Answer to Question 54)


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

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

public class Agg{
static public long i=10;
public static void main(String argv[]){
switch(i){
default:
System.out.println("no value given");
case 1: 
System.out.println("one");
case 10:
System.out.println("ten");
case 5:
System.out.println("five");
}
}
}
1) Compile time error
2) Output of "ten" followed by "five"
3) Output of "ten"
4) Compilation and run time error because of location of default

Answer to Question 55)


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

Question 56)
Given the following class

public class ZeroPrint{
public static void main(String argv[]){
int i =0;
//Here 
}
}
Which of the following lines if placed after the comment //Here will print out 0.

1) System.out.println(i++);
2) System.out.println(i+'0'); 
3) System.out.println(i);
4) System.out.println(i--);

Answer to Question 56)


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

Question 57)
Given the following code

class Base {}

class Agg extends Base{
public String getFields(){
String name = "Agg";
return name;
}
}

public class Avf{

public static void main(S

class Agg extends Base{
public String getFields(){
String name = "Agg";
return name;
}
}

public class Avf{

public static void main(String argv[]){
Base a = new Agg();
//Here
}
}
What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"?

1) System.out.println(a.getFields());
2) System.out.println(a.name);
3) System.out.println((Base) a.getFields());
4) System.out.println( ((Agg) a).getFields());

Answer to Question 57) 







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

public class Pvf{

static boolean Paddy;
public static void main(String argv[]){
System.out.println(Paddy);
}

}
1) Compile time error
2) compilation and output of false
3) compilation and output of true
4) compilation and output of null

Answer to Question 58)


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

Question 59)
Which of the following statements are true?

1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods
2) The x,y coordinates of an instance of MouseEvent can be obtained using the X and Y integer fields
3) The time of a MouseEvent can be extracted using the getTime() method 
4) The time of a MouseEvent can be extracted using the when parameter of the MouseEvent constructor

Answer to Question 59)


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

Question 60)
Given the following code 

import java.io.*;

public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
p.fliton();
}
public int fliton(){
try{
FileInputStream din = new FileInputStream("Ppvg.java");
din.read();
}catch(IOException ioe){

System.out.println("flytwick");
return 99;
}fin");
return 99;
}finally{

System.out.println("fliton");
}

return -1;
}

}

Assuming the file Ppvg.java is available to be read which of the following statements are true if you try to compile and run the program?

1) The program will run and output only "flytwick"
2) The program will run and output only "fliton"
3) The program will run and output both "fliton" and "flytwick"
4) An error will occur at compile time because the method fliton attempts to return two values

Answer to Question 60)


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

Answers
Answer to Question 1)

Objective 4.5)

1) float f=1/3; 
2) int i=1/3; 
4) double d=999d;

The fact that option 3 does not compile may be a surprise. The problem is because the default type for a number with a decimal component is a double and not a float. The additional trailing d in the option with 999 doesn't help, but it doesn't harm.

http://www.jchq.net/tutorial/04_05Tut.htm


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

Answer to Question 2)

Objective 4.3)

2) new

The option NULL (note the upper case letter) is definitely not a keyword. There is some discussion as to i. There is some discussion as to if null is a keyword but for the purpose of the exam you should probably assume it is a keyword.

The option instanceOf is a bit of a misleading option that would probably not occur on the exam. The real keyword is instanceof (note that the of has no capital letter O). I had the incorrect version in an earlier version of this tutorial as it looks more likely to my eyes. The instanceof keyword looks like a method, but it is actually an operator.

The option wend is probably valid in some other language to indicate the end of a while loop, but Java has no such keyword.

http://www.jchq.net/tutorial/04_03Tut.htm


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

Answer to Question 3)

Objective 4.5)

1) System.out.println(1+1); 
2) int i=2+'2'; 
Option 3 is not valid because single quotes are used to indicate a character constant and not a string. Several people have emailed me to say that option 3 will compile. When they eventually compiled the exact code they have agreed, it will not compile. Let me re-state that

String s="on"+'one';

Will NOT compile.

Option 4 will not compile because 255 is out of the range of a byte

http://www.jchq.net/tutorial/04_05Tut.htm







Answer to Question 4)

Objective 7.1)

1) The garbage collection algorithm in Java is vendor implemented

Threading and garbage collection are two of the few areas that are platform dependent. This is one of the 
reasons why Java is not suitable for realtime programming. It is not a good idea use it to control your 
plane or nuclear power station. Once an instance of the Integer class has a value it cannot be changed.

http://www.jchq.net/tutorial/07_01Tut.htm


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

Answer to Question 5)

Objective 10.1)

(Not on the official sub objectives but this topic does come up on the exam)

2) The RandomAccessFile class allows you to move directly to any point a file.
4) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system

The File class can be considered to represent information about a file rather than a real file object. You can create a file in the underlying operating system by passing an instance of a file to a stream such as FileOutputStream. The file will be created when you call the close method of the stream.

http://www.jchq.net/tutorial/10_01Tut.htm


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

Answer to Question 6)

⌨️ 快捷键说明

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