Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
FPL-II --- Unit 2 Question 154 Option A Option B Option C Option D Correct Answer Question 155 Option A Option B Option C Option D Correct Answer Question 156 Option A Option B Option C Option D Correct Answer Question 157 Option A Option B Option C Option D Correct Answer Question 158 2-57 JSPM’s RSCOE, Pune - 33 Consider the following program: import myLibrary.*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program? myLibrary.java ShowSomeClass.java ShowSomeClass ShowSomeClass.class B Consider the following code snippet String rive r = new String(“Columbia”); System.out.println(river.length()); What is printed? 6 7 8 Columbia C Consider public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write? MyClass mc = new MyClass(); MyClass mc = MyClass(); MyClass mc = MyClass; MyClass mc = new MyClass; A You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure? depth must be an int dive must be a method. dive must be the name of an instance field. submarine must be the name of a class B Guess the output of the following program. public class NumberSystem{ public static void main(String[]args) { int hexVal = 0x1a; System.out.println(“Value:”+hexVal); Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option A Option B Option C Option D Correct Answer Question 159 Option A Option B Option C Option D Correct Answer Question 160 2-58 JSPM’s RSCOE, Pune - 33 }} 25 32 26 24 C Guess the output of the following program. public class NumberSystem{ public static void main(String[]args) { int val = 0b11010; System.out.println(“Value:”+val); }} 32 28 64 26 D Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed? String str = new String(“Java”); char fourthChar = str.charAt(4); Option A Option B Option C Option D Correct Answer Question 161 Option A Option B Option C Option D Correct Answer ‘a’ ‘v’ throws StringIndexOutofBoundsException null character C public class test { static boolean fun(char ch) {System.out.println(ch); return true; } public static void main(String[] args) { int i=0; for(fun('P');fun('Q')&&(i<3);fun('R')) { i++; fun('S'); } } } PQRSPQRSPQRS PQSRQSRQSRQ Compilation Error None of these B Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Question 162 Option A Option B Option C Option D Correct Answer Question 163 Option A Option B Option C Option D Correct Answer Question 164 Option A Option B Option C Option D Correct Answer Question 165 Option A Option B Option C 2-59 JSPM’s RSCOE, Pune - 33 Consider, for(i=1,j=1;i<5;i++) j+=i; System.out.println(i); 4 5 6 None of these B What will be the output of this code? class Test { protected int x, y; } class Main { public static void main(String args[]) { Test t = new Test(); System.out.println(t.x + " " + t.y); } } 00 Compilation error Run time error None of these A class Main { public static void main(String args[]) { System.out.println(fun()); } int fun() { return 20; } } 20 Compilation error None of these Infinite loop B class Main { public static void main(String args[]) { System.out.println(fun()); } static int fun() { return 20; } } 20 Compilation error None of these Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option D Correct Answer Question 166 Option A Option B Option C Option D Correct Answer Question 167 Option A Option B Option C Option D Correct Answer Question 168 Option A Option B Option C Option D Correct Answer 2-60 JSPM’s RSCOE, Pune - 33 Infinite loop A class Test { public static void main(String args[]) { System.out.println(fun()); } static int fun() { static int x= 0; return ++x; } } 0 1 2 Compilation error D class Test { private static int x; public static void main(String args[]) { System.out.println(fun()); } static int fun() { x=2; return ++x; } } 2 3 4 Compilation error B class demo{ int a=4; public void show() { System.out.println(a); } public static void main(String args[]) { a++; show(); } } 4 5 6 Compilation error D Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Question 169 Option A Option B Option C Option D Correct Answer Question 170 Option A Option B Option C Option D Correct Answer Question 171 Option A Option B Option C Option D Correct Answer 2-61 JSPM’s RSCOE, Pune - 33 class Foo { public int a=3; public void addFive() { a+=5; System.out.print("f "); } public static void main(String[]args) { Foo f = new Foo(); f.addFive(); System.out.println(f.a); } } f 8 f8 None of these C class app { public static void main(String[] args) { char char1; char1 = 65; System.out.println("char1 + 1 = "+ char1 +1); } } char1 + 1 = a char1 + 1 = A char1 + 1 = A1 char1 + 1 = a1 C Consider the following code snippet. if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string"); What output do you think the code will produce if aNumber is 3? first string second string third string third string first string third string B Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Question 172 Option A Option B Option C Option D Correct Answer Question 173 Option A Option B Option C Option D Correct Answer Question 174 Option A Option B Option C Option D Correct Answer Question 175 2-62 JSPM’s RSCOE, Pune - 33 import java.util.*; class Pattern { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter N: "); int N=input.nextInt(); for(int i=1;i<=N;i++) { for(int j=0;j<N-i;j++) System.out.print(" "); for(int j=0;j<(2*i-1);j++) System.out.print("*"); System.out.println(); } } } What will be the output if N=3? * *** ***** * ** *** ***** Compilation error. A Consider the code: String x = new String("xyz"); String y = "abc"; x = x + y; How many String objects have been created? 2 3 4 5 C Consider the code: String x = new String("xyz"); String y = "abc"; x = x + y; What will be the output of the program? xyzabc xyz abc xyz abc A class BoolTest { public static void main(String [] args) { Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option A Option B Option C Option D Correct Answer Question 176 Option A Option B Option C Option D Correct Answer Question 177 Option A Option B Option C 2-63 JSPM’s RSCOE, Pune - 33 int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("ture"); if (b1.equals(b2) ) result = result + 1000; System.out.println("result = " + result); } } What will be the output of this code? result = 0 result = 1000 result = 2000 None of these A class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("true"); if (b1.equals(b2) ) result = result + 1000; System.out.println("result = " +result); } } What will be the output of this code? result = 0 result = 1000 result = 2000 None of these B class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("TRUE"); if (b1.equals(b2) ) result = result + 1000; System.out.println("result= "+(result+1000)); } } What will be the output of this code? result=0 result=1000 result=2000 Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option D Correct Answer Question 178 Option A Option B Option C Option D Correct Answer Question 179 Option A Option B Option C Option D Correct Answer Question 180 2-64 JSPM’s RSCOE, Pune - 33 None of these C class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("TRUE"); if (b1 == b2) result = 1; System.out.println("result = " + (result +1000)); }} result = 0 result = 1000 result = 1 result = 2000 B class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("true"); Boolean b3 = new Boolean("tRuE"); Boolean b4 = new Boolean("false"); if (b1 == b2) /* Line 10 */ result = 1; if (b1.equals(b2) ) /* Line 12 */ result = result + 10; if (b2 == b4) /* Line 14 */ result = result + 100; if (b2.equals(b4) ) /* Line 16 */ result = result + 1000; if (b2.equals(b3) ) /* Line 18 */ result = result + 10000; System.out.println("result = " + result); }} result = 0 result = 1 result = 10 result = 10010 D class ObjComp { public static void main(String [] args ) { int result = 0; ObjComp oc = new ObjComp(); Object o = oc; if (o == oc) result = 1; if (o != oc) Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option A Option B Option C Option D Correct Answer Question 181 Option A Option B Option C Option D Correct Answer Question 182 Option A Option B Option C Option D Correct Answer Question 183 Option A Option B Option C Option D 2-65 JSPM’s RSCOE, Pune - 33 result = result + 10; if (o.equals(oc) ) result = result + 100; if (oc.equals(o) ) result = result + 1000; System.out.println("result = " + result); }} result = 1 result = 10 result = 101 result = 1101 D String x = "xyz"; x.toUpperCase(); /* Line 2 */ String y = x.replace('Y', 'y'); y = y + "abc";/* Line 4 */ System.out.println(y); What will be the output of the program? abcXyZ abcxyz xyzabc XyZabc C int i = 1, j = 10; do { if(i++ > --j) /* Line 4 */ { continue; } } while (i < 5); System.out.println("i = " + i + "and j = " + j); /* Line 9 */ What will be the output of the program? i = 6 and j = 5 i = 5 and j = 5 i = 6 and j = 6 i = 5 and j = 6 D class Q207 { public static void main(String[] args) { int i1 = 5; int i2 = 6; String s1 = "7"; System.out.println(i1 + i2 + s1); /* Line 8 */ } } What will be the output of the program? 18 117 567 Compiler error Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Correct Answer Question 184 Option A Option B Option C Option D Correct Answer Question 185 Option A Option B Option C Option D Correct Answer Question 186 Option A Option B Option C Option D Correct Answer Question 187 Option A Option B Option C Option D Correct Answer Question 188 2-66 JSPM’s RSCOE, Pune - 33 B class SqrtExample { public static void main(String [] args) { double value = -9.0; System.out.println( Math.sqrt(value)); } } What will be the output of the program? 3.0 -3.0 NaN (Not a Number) Compilation fails. C String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s); What will be the output of the program? ABC abc ABCdef Compile Error C System.out.println(Math.sqrt(-4D)); What will be the output of the program? -2 NaN Compile Error Runtime Exception B String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a); What will be the output of the program? apa app apea apep B public class StringRef { public static void main(String [] args) { String s1 = "abc"; String s2 = "def"; String s3 = s2; /* Line 7 */ s2 = "ghi"; Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 2-67 JSPM’s RSCOE, Pune - 33 System.out.println(s1 + s2 + s3); Option A Option B Option C Option D Correct Answer Question 189 Option A Option B Option C Option D Correct Answer Question 190 Option A Option B Option C Option D Correct Answer Question 191 } } What will be the output of the program? abcdefghi abcdefdef abcghidef abcghighi C class Test138 { public static void stringReplace (String text) { text = text.replace ('j' , 'c'); /* Line 5 */ } public static void bufferReplace (StringBuffer text) { text = text.append ("c"); /* Line 9 */ } public static void main (String args[]) { String textString = new String ("java"); StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */ stringReplace(textString); bufferReplace(textBuffer); System.out.println (textString + textBuffer); } } java javac javajavac Compile error C String a = "ABCD"; String b = a.toLowerCase(); b.replace('a','d'); b.replace('b','c'); System.out.println(b); What will be the output of the program? abcd ABCD dccd dcba A public class ExamQuestion6 { static int x; boolean catch() { x++; return true; } public static void main(String[] args) { x=0; if ((catch() | catch()) || catch()) x++; System.out.println(x); } } What will be the output of the program? Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Option A Option B Option C Option D Correct Answer Question 192 Option A Option B Option C Option D Correct Answer Question 193 Option A Option B Option C Option D Correct Answer Question 194 Option A Option B Option C Option D Correct Answer 2-68 JSPM’s RSCOE, Pune - 33 1 2 3 Compilation Fails D String s = "hello"; Object o = s; if( o.equals(s) ) { System.out.println("A"); } else { System.out.println("B"); } if( s.equals(o) ) { System.out.println("C"); } else { System.out.println("D"); } What will be the output of the program? AC BD CD AB A Which will legally declare, construct, and initialize an array? int [] myList = {"1", "2", "3"}; int [] myList = (5, 8, 2); int myList [] [] = {4,9,7,0}; int myList [] = {4, 3, 7}; D public interface Foo { int k = 4; /* Line 3 */ } public interface Foo { int k = 4; /* Line 3 */ } Which three piece of codes are equivalent to line 3? 1. final int k = 4; 2. public int k = 4; 3. static int k = 4; 4. abstract int k = 4; 5. volatile int k = 4; 6. protected int k = 4; 1, 2 and 3 2, 3 and 4 3, 4 and 5 4, 5 and 6 A Compiled by : Prof. M. A. Ansari (Engineering Science Dept.) FPL-II --- Unit 2 Question 195 Option A Option B Option C Option D Correct Answer Question 196 Option A Option B Option C Option D Correct Answer Question 197 Option A Option B Option C Option D Correct Answer Question 198 Option A Option B Option C Option D Correct Answer Question 199 Option A Option B Option C Option D Correct Answer Question 200 Option A Option B Option C Option D Correct Answer 2-69 JSPM’s RSCOE, Pune - 33 Which one of the following will declare an array and initialize it with five numbers? Array a = new Array(5); int [] a = {23,22,21,20,19}; int a [] = new int[5]; int [5] array; B Which one is a valid declaration of a boolean? boolean b1 = 0; boolean b2 = 'false'; boolean b3 = false; boolean b4 = Boolean.false(); C switch(x) { default: System.out.println("Hello"); } Which two are acceptable types for x? byte and char long and float char and short float and long A public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even");} } Which statement is true? Compilation fails. "odd" will always be output. "even" will always be output. "odd" will be output for odd values of x, and "even" for even values. A public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } } Which statement is true? There is a syntax error on line 1. There are syntax errors on lines 1 and 6. There are syntax errors on lines 1, 6, and 8. There is a syntax error on line 6. D Which is valid declaration of a float? float f = 1F; float f = 1.0; float f = "1"; float f = 1.0d; A Compiled by : Prof. M. A. Ansari (Engineering Science Dept.)