// Questions from http://www.javaprepare.com/quests/test.html public class mytest extends multchoice { public final void loadtest() { // implements abstract method in multchoice q= new mcquestion[MAXQUESTIONS]; numq= 0; mcquestion newq; newq= new mcquestion("Which declaration of the main method below "+ "would allow a class to be started as a "+ "standalone program?", 5, false); newq.answer("public static int main(char args[]);", false); newq.answer("public static void main(String args[]); ", true); newq.answer("public static void MAIN(String args[]);", false); newq.answer("public static void main(String args);", false); newq.answer("public static void main(char args[]);", false); addquestion(newq); newq= new mcquestion("What all gets printed when the following code is "+ "compiled and run? Select all correct answers.\n"+ "\n"+ "public class xyz {\n"+ " public static void main(String args[]) {\n"+ " for(int i = 0; i < 2; i++) {\n"+ " for(int j = 2; j>= 0; j--) {\n"+ " if(i == j) break;\n"+ " System.out.println(\"i=\" + i + \" j=\"+j);\n"+ " }\n"+ " }\n"+ " }\n"+ "}", 9, false); newq.answer("i=0 j=0 ", false); newq.answer("i=0 j=1 ", true); newq.answer("i=0 j=2", true); newq.answer("i=1 j=0 ", false); newq.answer("i=1 j=1 ", false); newq.answer("i=1 j=2 ", true); newq.answer("i=2 j=0", false); newq.answer("i=2 j=1 ", false); newq.answer("i=2 j=2 ", false); addquestion(newq); // 3. newq= new mcquestion("What gets printed when the following code is "+ "compiled and run with the following command\n"+ "-\n"+ "java test 2\n"+ "Select the one correct answer.\n"+ "public class test {\n"+ " public static void main(String args[]) { \n"+ " Integer intObj=Integer.valueOf(args[args.length-1]);\n"+ " int i = intObj.intValue();\n"+ "\n"+ " if(args.length > 1)\n"+ " System.out.println(i);\n"+ " if(args.length > 0)\n"+ " System.out.println(i - 1);\n"+ " else \n"+ " System.out.println(i - 2);\n"+ " }\n"+ "} \n", 5, true); newq.answer("test", false); newq.answer("test -1", false); newq.answer("0", false); newq.answer("1 ", true); newq.answer("2 ", false); addquestion(newq); } /** constructor **/ public mytest() { } }