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

📄 scjp试题-scjpmockexam3.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 4 页
字号:
1) If multiple listeners are added to a component only events for the last listener added will be processed
2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
3) Adding multiple listeners to a comnponent will cause a compile time error
4) You may remove as well add listeners to a component.

Answer to Question 40)


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

Question 41)
Given the following code

class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}

Which of the following, if inserted at the comment //Here will allow the code to compile and run without error

1) b=m;
2) m=b;
3) d =i;
4) b1 =i;

Answer to Question 41)


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

Question 42)
Which of the following statements about threading are true

1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a synchronized method of an object 
4) Thread scheduling algorithms are platform dependent

Answer to Question 42)






Question 43)
Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.

The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?


1) Give the goahead for further design using the current scheme
2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
3) Ask for the option of WindowsPC to be removed as it will soon be obsolete
4) Change the hierarchy to remove the need for the superfluous Computer Class.


Answer to Question 43)


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

Question 44)
Which of the following statements are true

1) An inner class may be defined as static
2) There are NO circumstances where an inner class may be defined as private
3) An anonymous class may have only one constructor
4) An inner class may extend another class

Answer to Question 44)


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

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

int Output=10;
boolean b1 = false;
if((b1==true) && ((Output+=10)==20)){
System.out.println("We are equal "+Output);
}else
{
System.out.println("Not equal! "+Output);
}
1) Compile error, attempting to peform binary comparison on logical data type
2) Compilation and output of "We are equal 10"
3) Compilation and output of "Not equal! 20"
4) Compilation and output of "Not equal! 10"

Answer to Question 45)


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

Question 46)
Given the following variables which of the following lines will compile without error?

String s = "Hello";
long l = 99;
double d = 1.11;
int i = 1;
int j = 0;
1) j= i <
Answer 
to Question 46)
--------------------------------------------------------------------------------

Question 47)
What will be output by the following line of code?
System.out.println(010|4);
1) 142) 03) 64) 12
Answer 
to Question 47)
--------------------------------------------------------------------------------

Question 48)
Given the following variableschar c = 'c';
int i = 10;
double d = 10;
long l = 1;
String s = "Hello";
Which of the following will compile without error?
1)c=c+i; 2)s+=i; 3)i+=s; 4)c+=s;
Answer 
to Question 48)
--------------------------------------------------------------------------------

Question 49)
Which of the following will compile without error?
1) File f = new File("/","autoexec.bat");2) DataInputStream d = new 
DataInputStream(System.in);3) OutputStreamWriter o = new 
OutputStreamWriter(System.out);4) RandomAccessFile r = new 
RandomAccessFile("OutFile");
Answer 
to Question 49)
--------------------------------------------------------------------------------

Question 50)
Given the folowing classes which of the following will compile without 
error?interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}

1)o1=o2;
2)b=ob;
3)ob=b;
4)o1=b;
Answer 
to Question 50)





Question 51)
Given the following code what will be the output?class ValHold{
public int i = 10;
}

public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod

public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another

}
1) 10,0, 302) 20,0,303) 20,99,304) 10,0,20
Answer 
to Question 51)
--------------------------------------------------------------------------------

Question 52)
Given the following class definition, which of the following methods could be 
legally placed after the comment//Here 
public class Rid{
public void amethod(int i, String s){}
//Here
}
1)public void amethod(String s, int i){}2)public int amethod(int i, 
String s){} 3)public void amethod(int i, String mystring){} 4) public 
void Amethod(int i, String s) {}
Answer 
to Question 52)
--------------------------------------------------------------------------------

Question 53)
Given the following class definition which of the following can be legally 
placed after the comment line//Here ?class Base{
public Base(int i){}
}



public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
}
MyOver(int i){
super(i);
}

MyOver(String s, int i){
this(i);
//Here
}
}
1)MyOver m = new MyOver();2)super(); 3)this("Hello",10);4)Base b 
= new Base(10);
Answer 
to Question 53)
--------------------------------------------------------------------------------

Question 54)
Given the following class definition, which of the following statements would 
be legal after the comment //Hereclass InOut{

String s= new String("Between");
public void amethod(final int iArgs){
int iam;
class Bicycle{
public void sayHello(){
//Here
}//End of bicycle class
}
}//End of amethod
public void another(){
int iOther;
}

}
1)System.out.println(s); 2) System.out.println(iOther);3) 
System.out.println(iam);4) System.out.println(iArgs);
Answer 
to Question 54)
--------------------------------------------------------------------------------

Question 55)
Which of the following are methods of the Thread class?
1) yield()2) sleep(long msec)3) go()4) stop()
Answer 
to Question 55)
--------------------------------------------------------------------------------

Question 56)
Which of the following methods are members of the Vector class and allow you 
to input a new element
1) addElement2) insert3) append4) addItem
Answer 
to Question 56)
--------------------------------------------------------------------------------

Question 57)
Which of the following statements are true?
1) Adding more classes via import statements will cause a performance 
overhead, only import classes you actually use.2) Under no circumstances can 
a class be defined with the private modifier3) A inner class may 
under some circumstances be defined with the protected modifier4) An 
interface cannot be instantiated
Answer 
57)
--------------------------------------------------------------------------------

Question 58)
Which of the following are correct event handling methods
1) mousePressed(MouseEvent e){}2) MousePressed(MouseClick e){}3) 
functionKey(KeyPress k){}4) componentAdded(ContainerEvent e){}
Answer 
58)
--------------------------------------------------------------------------------

Question 59)
Which of the following are methods of the Collection interface?1) 
iterator2) isEmpty3) toArray4) setText
Answer 
59)
--------------------------------------------------------------------------------

Question 60)
Which of the following best describes the use of the synhronized keyword?
1) Allows two process to run in paralell but to communicate with each 
other2) Ensures only one thread at a time may access a method or 
object3) Ensures that two or more processes will start and end at the same 
time4) Ensures that two or more Threads will start and end at the same 
time
Answer 
60)





Answers
--------------------------------------------------------------------------------

Answer 1)
Objective 1.2)
1) The code will compile and run, printing out the words "My Func"
A class that contains an abstract method must be declared abstract itself, 
but may contain non abstract methods.
--------------------------------------------------------------------------------

Answer 2)
Objective 4.1)
4) The code will compile but will complain at run time that main is not 
correctly defined
In this example the parameter is a string not a string array as needed for 
the correct main method
--------------------------------------------------------------------------------

Answer 3)
Objective 4.3)
1) public2) private4) transient
The keyword transient is easy to forget as is not frequently used. Although a 
method may be considered to be friendly like in C++ it is not a Java 
keyword.
--------------------------------------------------------------------------------

Answer 4)
Objective 1.2)
2) The compiler will complain that the Base class is not declared as 
abstract.
If a class contains abstract methods it must itself be declared as 
abstract
--------------------------------------------------------------------------------

Answer 5)
Objective 1.2)
1) To get to access hardware that Java does not know about3) To write 
optimised code for performance in a language such as C/C++
--------------------------------------------------------------------------------

Answer 6)
Objective 1.2)
4) Success in compilation and output of "amethod" at run time.
A final method cannot be ovverriden in a sub class, but apart from that it 
does not cause any other restrictions.
--------------------------------------------------------------------------------

Answer 7)
Objective 1.2)
4) Compilation and execution without error
It would cause a run time error if you had a call to amethod though.
--------------------------------------------------------------------------------

Answer 8)
Objective 1.2)
1)Compile time error: Base cannot be private
A top leve (non nested) class cannot be private.
--------------------------------------------------------------------------------

Answer 9)
Objective 1.2)
4) P1 compiles cleanly but P2 has an error at compile time
The package statement in P1.java is the equivalent of placing the file in a 
different directory to the file P2.java and thus when the compiler tries to 
compile P2 an error occurs indicating that superclass P1 cannot be found.
--------------------------------------------------------------------------------

Answer 10)
Objective 1.1)
2) An error at run time
This code will compile, but at run-time you will get an ArrayIndexOutOfBounds 
exception. This becuase counting in Java starts from 0 and so the 5th element of 
this array would be i[4].
Remember that arrays will always be initialized to default values wherever 
they are created.
--------------------------------------------------------------------------------

Answer 11)
Objective 1.1)
2)myarray.length;
The String class has a length() method to return the number of characters. I 
have sometimes become confused between the two.
--------------------------------------------------------------------------------

Answer 12)
Objective 8.2)

⌨️ 快捷键说明

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