?? mockcert03.txt
字號:
Mutiple:
1) private class MyClass extends Object
2) class myclass extends Object
3) public class MyClass
4) public class MyClass extends Object
Question 24
===========================================================
Once created, some Java objects are "immutable", meaning they can not have their contents changed. Which of the following classed produce immutable objects?
Mutiple:
1) java.lang.Double
2) java.lang.StringBuffer
3) java.lang.Boolean
4) java.lang.Math
Question 25
===========================================================
Given the following class definitions:
1. class BaseWidget extends Object{
2. String name="BaseWidget";
3. void speak(){System.out.println("I am a "+name);}
4. }
5. class TypeAWidget extends BaseWidget{
6. TypeAWidget()
{name="TypeA";}
7. }
Which of the following code fragments will compile and execute without error?
Mutiple:
1) Object A=new BaseWidget();
A.speak();
2) BaseWidget B=new TypeAWidget();
B.speak();
3) TypeAWidget C=new BaseWidget();
C.speak();
Question 26
===========================================================
Pick the keyword(s) which can NOT be used as modifiers in declaration of a method in a Java class.
Mutiple:
1) private
2) friend
3) protected
4) static
5) synchronized //答案不對吧?此字可以修飾method啊?
Question 27
===========================================================
Which of the following would be an illegal identifier for a Java method?
Mutiple:
1) do_it_now
2) _Substitute
3) 9thMethod
4) $addMoney
5) %getPath
Question 28
===========================================================
Given the following code for the Demo class:
public class Demo{
private int[] count;
public Demo(){ count=new int[10];}
public void setCount(int ct,int n){ count[n]=ct;}
public void showCount(int n){
System.out.println("Count is "+count[n]);
}
public int getCount(int n){ return count[n];}
}
what would be the result of calling the showCount method with a parameter of 9 immediately after creating an instance of Demo?
Mutiple:
1) A NullPointerException would be thrown, halting the program.
2) Standard output would show "Count is 0".
3) An ArrayIndexOutOfBoundsException would be thrown, halting the program.
4) Standard output would show "Count is null".
Question 29
===========================================================
What happens when we attempt to compile and run the following code?
1. public class Logic{
2. static long sixteen=0x0010;
3. static public void main(String args[]){
4. long N=sixteen>>4:
5. System.out.println("N= "+N);
6. }
7. }
Mutiple:
1) The compiler will object to line 4 combining a long with an int.
2) The program will compile and run, producing the output "N=0".
3) The program will compile and run, producing the output "N=1".
4) A rutime exception will be thrown.
Question 30
===========================================================
What will happen on trying to compile and run the following application?
1. public class Example{
2. public Boolean flags[]=new Boolean[4];
3. public static void main(String[] args){
4. Example E=new Example();
5. System.out.println("Flag 1 is "+E.flags[1]);
6. }
7. }
Mutiple:
1) The text "Flag 1 is true" will be written to standard output.
2) The text "Flag 1 is false" will be written to standard output.
3) The text "Flag 1 is null" will be written to standard output.
4) The compiler will object to line 2.
Question 31
===========================================================
Which of the following code fragments are legal Java code?
Mutiple:
1) String A="abcdefg";
A-="cde";
2) String A="abcdefg";
A+="cde";
3) Integer J=new Integer(27);
J-=7;
4) Integer J=new Integer(27);
J--;
Question 32
===========================================================
Given the following code for the code for Demo class, where "XXXX" represents an access modifier:
public class Demo extends Base{
XXXX String userName;
public void setName(String s){ userName=s;}
public void showName(){
System.out.println("Name is "+userName):
}
public String getName(){ return userName; }
}
Select the modifier which would be used to give only classes in the default package or classes derived from Demo, direct access to the userName String variable.
Mutiple:
1) public
2) blank (ie - the line would read "String userName :")
3) protected
4) private
Question 33
===========================================================
Given the following method in an application:
1. public String setFiletype(String fname){
2. int p=fname.indexOf('.');
3. if(p>0) fname=fname.substring(0,p);
4. fname+=".TXT";
5. return fname;
6. }
and given that another part of the class has a the following code:
7. String TheFile="Program.java";
8. File F=new File(setFileType(TheFile));
9. System.out.println("Created "+TheFile);
What will be printed by the statement in line 9?
Mutiple:
1) "Created Program.java"
2) "Created Program.txt"
3) "Created Program.java.txt"
Question 34
===========================================================
What happens on trying to compile and run the following code?
1. public class EqualsTest{
2. public static void main(String args[]){
3. byte A=(byte)4096;
4. if(A==4096)System.out.println("Equal");
5. else System.out.println("Not Equal");
6. }
7. }
Mutiple:
1) The compiler objects to the loss of accurcy in the cast in line 3.
2) The program compiles and prints "Not Equal".
3) The program compiles and prints "Equal".
Question 35
===========================================================
What happens on trying to compile and run the following code?
1. public class EqualsTest{
2. public static void main(String args[]){
3. Long LA=new Long(7);
4. Long LB=new Long(7);
5. if(LA==LB) System.out.println("Equal");
6. else System.out.println("Not Equal");
7. }
8. }
Mutiple:
1) The program compiles but throws a runtime exception in line 5.
2) The program compiles and prints "Not Equal";
3) The program compiles and prints "Equal".
Question 36
===========================================================
Given the following code for the Demo class:
public class Demo extends Base{
private int count;
public Demo(){
System.out.println("A Demo object has been created");
}
protected void addOne() {count++; }
}
Which of the following statements about the "count" variable is correct?
Mutiple:
1) When a new Demo object is created, the value of count is zero.
2) When a new Demo object is created, the value of count is undefined.
3) An object of the Base class can have methods which modify the count variable.
4) The only way the count variable can be modified is by calling the addOne method.
Question 37
===========================================================
Which of the following statements will cause a compiler error.
Mutiple:
1) float F=4096.0;
2) double D=4096.0;
3) byte B=4096;
4) char C=4096;
Question 38
===========================================================
In the following method, which may be called with any kind of Object, we want to "short circuit" the logical test in line 2 if the object is not a Long. Which logical operator should replace the X in line 2 to accomplish this?
1. long Test(Object ob){
2. if(Ob instanceof Long X ((Long)Ob).longValue()>999){
3. return((Long)Ob).longValue();
4. }
5. return -1L;
6. }
Mutiple:
1) Replace 'X' with '&&'.
2) Replace 'X' with '||'.
3) Replace 'X' with '&'.
4) Replace 'X' with '|'.
Question 39
===========================================================
Which of the following statements is the correct form fro determining whether the float primitive X has the specail "Not a Number" value?
Mutiple:
1) if(X instanceof Float.NaN)
2) if(X==Float.NaN)
3) if(Float.isNaN(X))
Question 40
===========================================================
Which of the following are organizing principles of Java's "javadoc" format documentation for a given class?
Mutiple:
1) Relative frequency of use of the various methods.
2) Lists of methods in a class in alphabetic order.
3) Separate listing of private, protected and public methods in a calss.
Question 41
===========================================================
The following program is compiled and then run with this command line:
java Demo alpha beta gamma
public class Demo{
public static void main(String args[]){
int n=3;
System.out.println("The word is "+args[n]);
}
}
What happens?
Mutiple:
1) "The word is beta" is written to standard output.
2) "The word is gamma" is written to standard output.
3) The runtime system reports an ArrayIndexOutOfBoundsException in the main method.
4) The runtime system reports a NullPointerException in the main method.
Question 42
===========================================================
What will be the result of running the following method with an input of 67?
public int MaskOff(int N){
return N^3;
}
Mutiple:
1) The method will return 3.
2) The method will return 64.
3) The method will return 67.
4) The method will return 0.
Question 43
===========================================================
What happens on trying to compile and run the following code?
public class EqualsTest{
public static void main(String args[]){
char A='\u0005';
if(A==0x0005L) System.out.println("Equal");
else System.out.println("Not Equal");
}
}
Mutiple:
1) The compiler reports "Invalid character in input" in line 3.
2) The program compiles and prints "Not Equal".
3) The program compiles and prints "Equal".
Question 44
===========================================================
Which of the following Java statements correctly declare an array of int primitives?
Mutiple:
1) int scores[];
2) int[] scores;
3) int scores={0,0,0,0};
Question 45
===========================================================
Assume that the following program has been compiled and the Demo.class file is in the current directory.
public class Demo{
public static void main(String args[]){
int n=1;
System.out.println("The word is "+args[n]);
}
}
Select the correct command line to execute the program and produce the following output line: "The word is gamma"
Mutiple:
1) Demo alpha beta gamma delta
2) java Demo alpha beta gamma delta
3) java Demo beta gamma delta
4) java Demo.class beta gamma delta
5) java Demo.class alpha beta gamma delta
Question 46
===========================================================
What happens on trying to compile and run the following code?
public class EqualsTest{
public static void main(String args[]){
Object A=new Long(7);
Long L=new Long(7);
if(A.equals(L)) System.out.println("Equal");
else System.out.println("Not Equal");
}
}
Mutiple:
1) The program compiles and prints "Equal".
2) The program compiles and prints "Not Equal".
3) The compiler objects to line 5.
4) A runtime cast error occurs at line 5.
Question 47
===========================================================
What will be the result of compiling the following code?
public class SiteInfo{
String webSite="http://www.lanw.com"+'/'+"default.htm";
public String getSite(){
return webSite;
}
}
Mutiple:
1) The code will compile without problem.
2) The compiler will report an error " ':' expected" for the statement in line 2.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -