(Quiz) 10 Java Multiple Choice Questions
Quiz : 10 Java Multiple Choice Questions
Question 1
Which code segment could execute the stored procedure "countRecs()" located in a database server?
1) Statement stmt = connection.createStatement();
stmt.execute("COUNTRECS()");
2) CallableStatement cs = con.prepareCall("{call COUNTRECS}");
cs.executeQuery();
3) StoreProcedureStatement spstmt = connection.createStoreProcedure("countRecs()");
spstmt.executeQuery();
4) PrepareStatement pstmt = connection.prepareStatement("countRecs()");
pstmt.execute();
5) Statement stmt = connection.createStatement();
stmt.executeStoredProcedure("countRecs()");
Question 2
if(check4Biz(storeNum) != null) {}
Referring to the above, what datatype could be returned by method check4Biz()?
1) Boolean
2) int
3) String
4) char
5) byte
Question 3
int j;
for(int i=0;i<14;i++) {
if(i<10) {
j = 2 + i;
}
System.out.println("j: " + j + " i: " + i);
}
What is WRONG with the above code?
1) Integer "j" is not initialized.
2) Nothing.
3) You cannot declare integer i inside the for-loop declaration.
4) The syntax of the "if" statement is incorrect.
5) You cannot print integer values without converting them to strings.
Question 4
Which one of the following is a valid declaration of an applet?
1) Public class MyApplet extends java.applet.Applet {
2) Public Applet MyApplet {
3) Public class MyApplet extends applet implements Runnable {
4) Abstract class MyApplet extends java.applet.Applet {
5) Class MyApplet implements Applet {
Question 5
int values[] = {1,2,3,4,5,6,7,8};
for(int i=0;i< X; ++i)
System.out.println(values[i]);
Referring to the above, what value for X will print all members of array "values"?
1) 1
2) 7
3) 8
4) 9
5) None, since there is a syntax error in the array declaration
Question 6
public int m1(int x) {
int count=1;
try {
count += x;
count += m2(count);
count++;
}
catch(Exception e) { count -= x; }
return count;
}
Referring to the above, when m1(2) is invoked, m2() throws an ArithmeticException and m1() returns which one of the following?
1) 1
2) 2
3) 3
4) 4
5) The system will exit
Question 7
System.getProperties().put(
"java.rmi.server.codebase",
"http://www.domain.com/classes/");
Which one of the following is a capability of the above code?
1) Override CLASSPATH
2) Register an rmi server on its host system
3) Set the location of all applets in a web server
4) Append CLASSPATH
5) Facilitate dynamic class loading for remote objects
Question 8
Which one of the following statements is FALSE?
1) Java supports multi-threaded programming.
2) Threads in a single program can have different priorities.
3) Multiple threads can manipulate files and get user input at the same time.
4) Two threads can never act on the same object at the same time.
5) Threads are created and started with different methods.
Question 9
1 public static void main(String[] s) {
2 String n1, n2, n3;
3 n1 = "n1";
4 n2 = "n2";
5 n3 = "n3";
6 {
7 String n4 = "inner";
8 n2 = n1;
9 }
10 n3 = null;
11 }
How many instances of the String will be eligible for garbage collection after line 10 in the above code snippet is executed?
1) 0
2) 1
3) 2
4) 3
5) The code will not compile.
Question 10
Which code declares class A to belong to the mypackage.financial package?
1) package mypackage;
package financial;
2) import mypackage.*;
3) package mypackage.financial.A;
4) import mypackage.financial.*;
5) package mypackage.financial;
- guru's blog
- Login to post comments

Need answers
Please anybody give answers of all these question. thanks in advance.