Question 27)
Which of the following is the correct syntax for suggesting that the JVM performs garbage collection
1) System.free();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();
Question 28)
What will happen when you attempt to compile and run the following code
public class As{ int i = 10; int j; char z= 1; boolean b; public static void main(String argv[]){ As a = new As(); a.amethod(); } public void amethod(){ System.out.println(j); System.out.println(b); }}
1) Compilation succeeds and at run time an output of 0 and false
2) Compilation succeeds and at run time an output of 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value
Question 29)
What will happen when you attempt to compile and run the following code with the command line "hello there"
public class Arg{String[] MyArg; public static void main(String argv[]){ MyArg=argv; } public void amethod(){ System.out.println(argv[1]); }}
1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above
Question 30)
What will happen when you attempt to compile and run the following code
public class StrEq{public static void main(String argv[]){ StrEq s = new StrEq(); } private StrEq(){ String s = "Marcus"; String s2 = new String("Marcus"); if(s == s2){ System.out.println("we have a match"); }else{ System.out.println("Not equal"); } }}
1) Compile time error caused by private constructor
2) Output of "we have a match"
3) Output of "Not equal"
4) Compile time error by attempting to compare strings using
责任编辑:cyth