Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 4 fuera de 309 páginas
Examen

Core Java Assessment MCQS 1

Document preview thumbnail
Vista previa 4 fuera de 309 páginas

QuestionText QuestionType Choice1 Choice2 Choice3 Choice4 Choice5 Grade1 Grade2 Grade3 Grade4 Grade5 "What will be the result of compiling the following program? public class MyClass { long var; public void MyClass(long param) { var = param; } // (Line no 1) public static void main(String[] args) { MyClass a, b; a = new MyClass(); // (Line no 2) } }" MCQ A compilation error will occur at (Line no 1), since constructors cannot specify a return value A compilation error will occur at (2), since the class does not have a default constructor A compilation error will occur at (Line no 2), since the class does not have a constructor that takes one argument of type int. The program will compile without errors. 0 0 0 1 Which of the following declarations are correct? (Choose TWO) MCA boolean b = TRUE; byte b = 256; String s = “null”; int i = new Integer(“56”); 0 0 0.5 0.5 "What will happen when you attempt to compile and run this code? abstract class Base{ abstract public void myfunc(); public void another(){ Sln(""Another method""); } } public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); od(); } public void myfunc(){ Sln(""My Func""); } public void amethod(){ myfunc(); } }" MCQ The code will compile and run, printing out the words "My Func" The compiler will complain that the Base class has non abstract methods The code will compile but complain at run time that the Base class has non abstract methods The compiler will complain that the method myfunc in the base class has no body, nobody at all to print it 1 0 0 0 class A, B and C are in multilevel inheritance hierarchy repectively . In the main method of some other class if class C object is created, in what sequence the three constructors execute? MCQ Constructor of A executes first, followed by the constructor of B and C Constructor of C executes first followed by the constructor of A and B Constructor of C executes first followed by the constructor of B and A Constructor of A executes first followed by the constructor of C and B 1 0 0 0 "Consider the following code and choose the correct option: package aj; private class S{ int roll; S(){roll=1;} } package aj; class T { public static void main(String ar[]){ S(new S().roll);}}" MCQ Compilation error Compiles and display 1 Compiles but no output Compiles and diplay 0 1 0 0 0 "Here is the general syntax for method definition: accessModifier returnType methodName( parameterList ) { Java statements return returnValue; } What is true for the returnType and the returnValue?" MCQ The returnValue can be any type, but will be automatically converted to returnType when the method returns to the caller If the returnType is void then the returnValue can be any type The returnValue must be the same type as the returnType, or be of a type that can be converted to returnType without loss of information The returnValue must be exactly the same type as the returnType. 0 0 1 0 "A) A call to instance method can not be made from static context. B) A call to static method can be made from non static context." MCQ Both are FALSE Both are TRUE Only A is TRUE Only B is TRUE 0 1 0 0 "Consider the following code and choose the correct option: class A{ A(){S(""From A"");}} class B extends A{ B(int z){z=2;} public static void main(String args[]){ new B(3);}}" MCQ Compilation error Comiples and prints From A Compiles but throws runtime exception Compiles and display 3 0 1 0 0 "class Sample {int a,b; Sample() { a=1; b=2; Sln(a+""t""+b); } Sample(int x) { this(10,20); a=b=x; Sln(a+""t""+b); } Sample(int a,int b) { this(); this.a=a; this.b=b; Sln(a+""t""+b); } } class This2 { public static void main(String args[]) { Sample s1=new Sample (100); } } What is the Output of the Program?" MCQ 20 20 100 100 0 0 0 1 "Consider the following code and choose the correct option: class A{ private static void display(){ S(""Hi"");} public static void main(String ar[]){ display();}}" MCQ Compiles and display Hi Compiles and throw run time exception Compiles but doesn't display anything Compilation fails 1 0 0 0 "Consider the following code and choose the correct option: package aj; class A{ protected int j; } package bj; class B extends A { public static void main(String ar[]){ S(new A().j=23);}}" MCQ code compiles fine and will display 23 code compiles but will not display output compliation error j can not be initialized 0 0 1 0 "Consider the following code and choose the correct option: class A{ int z; A(int x){z=x;} } class B extends A{ public static void main(String arg){ new B();}}" MCQ Compilation error Compiles but throws run time exception Compiles and displays nothing None of the listed options 1 0 0 0 "class Test{ static void method(){ ay(); } static display(){ Sln((""hello""); } public static void main(String[] args){ new Test().method(); } } consider the code above & select the proper output from the options." MCQ hello Runtime Error compiles but no output does not compile 0 0 0 1 "What will be the result when you try to compile and run the following code? private class Base{ Base(){ int i = 100; Sln(i); } } public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); Sln(i); } }" MCQ 200 100 followed by 200 Compile time error 100 0 0 1 0 "public class MyClass { static void print(String s, int i) { Sln(""String: "" + s + "", int: "" + i); } static void print(int i, String s) { Sln(""int: "" + i + "", String: "" + s); } public static void main(String[] args) { print(""String first"", 11); print(99, ""Int first""); } }What would be the output?" MCQ String: String first, int: 11 int: 99, String: Int first int: 27, String: Int first String: String first, int: 27 Compilation Error Runtime Exception 1 0 0 0 "A) No argument constructor is provided to all Java classes by default B) No argument constructor is provided to the class only when no constructor is defined. C) Constructor can have another class object as an argument D) Access specifiers are not applicable to Constructor" MCQ Only A is TRUE All are TRUE B and C is TRUE All are FALSE 0 0 1 0 "Consider the following code and choose the correct option: class Test{ private static void display(){ Sln(""Display()"");} private static void show() { display(); Sln(""show()"");} public static void main(String arg[]){ show();}}" MCQ Compiles and prints show() Compiles and prints Display() show() Compiles but throws runtime exception Compilation error 0 1 0 0 "Which of the following sentences is true? A) Access to data member depends on the scope of the class and the scope of data members B) Access to data member depends only on the scope of the data members C) Access to data member depends on the scope of the method from where it is accessed" MCQ Only A and C is TRUE All are TRUE All are FALSE Only A is TRUE 0 0 0 1 "Given: public class Yikes { public static void go(Long n) {S(""Long "");} public static void go(Short n) {S(""Short "");} public static void go(int n) {S(""int "");} public static void main(String [] args) { short y = 6; long z = 7; go(y); go(z); } } What is the result?" MCQ int Long Short Long Compilation fails. An exception is thrown at runtime. 1 0 0 0 Which of the following will print -4.0 MCQ Sln(M(-4.7)); Sln(M(-4.7)); Sln(M(-4.7)); Sln(M(-4.7)); 1 0 0 0 "Suppose class B is sub class of class A: A) If class A doesn't have any constructor, then class B also must not have any constructor B) If class A has parameterized constructor, then class B can have default as well as parameterized constructor C) If class A has parameterized constructor then call to class A constructor should be made explicitly by constructor of class B" MCQ Only B and C is TRUE Only A is TRUE All are FALSE Only A and C is TRUE 1 0 0 0 "class Order{ Order(){ Sln(""Cat""); } public static void main(String... Args){ Sln(""Ant""); } static{ Sln(""Dog""); } { Sln(""Man""); }} consider the code above & select the proper output from the options." MCQ Dog Ant Dog Man Cat Ant Man Dog Ant Dog Man Ant 1 0 0 0 "Consider the following code and choose the correct option: class A{ private void display(){ S(""Hi"");} public static void main(String ar[]){ display();}}" MCQ Compiles but doesn't display anything Compiles and throws run time exception Compilation fails Compiles and displays Hi 0 0 1 0 "Consider the following code and choose the correct option: public class MyClass { public static void main(String arguments[]) { amethod(arguments); } public void amethod(String[] arguments) { Sln(arguments[0]); Sln(arguments[1]); } } Command Line arguments - Hi, Hello" MCQ prints Hi Hello Compiler Error Runs but no output Runtime Error 0 1 0 0 "package QB; class Sphere { protected int methodRadius(int r) { Sln(""Radious is: ""+r); return 0; } } package QB; public class MyClass { public static void main(String[] args) { double x = 0.89; Sphere sp = new Sphere(); // Some code missing } } to get the radius value what is the code of line to be added ?" MCQ methodRadius(x); dRadius(x); Nothing to add SdRadius(); 0 1 0 0 "class One{ int var1; One (int x){ var1 = x; }} class Derived extends One{ int var2; void display(){ Sln(""var 1=""+var1+""var2=""+var2); }} class Main{ public static void main(String[] args){ Derived obj = new Derived(); ay(); }} consider the code above & select the proper output from the options." MCQ 0 , 0 compiles successfully but runtime error compile error none of these 0 0 1 0 "Consider the following code and choose the correct option: class Test{ private void display(){ Sln(""Display()"");} private static void show() { display(); Sln(""show()"");} public static void main(String arg[]){ show();}}" MCQ Compiles and prints show() Compiles and prints Display() show() Compiles but throws runtime exception Compilation error 0 0 0 1 "Consider the following code and choose the best option: class Super{ int x; Super(){x=2;}} class Sub extends Super { void displayX(){ S(x);} public static void main(String args[]){ new Sub().displayX();}}" MCQ Compilation error Compiles and runs without any output Compiles and display 2 Compiles and display 0 0 0 1 0 "class One{ int var1; One (int x){ var1 = x; }} class Derived extends One{ int var2; Derived(){ super(10); var2=10; } void display(){ Sln(""var1=""+var1+"" , var2=""+var2); }} class Main{ public static void main(String[] args){ Derived obj = new Derived(); ay(); }} consider the code above & select the proper output from the options." MCQ var1=10 , var2=10 0,0 compile error runtime error 1 0 0 0 "public class MyAr { static int i1; public static void main(String argv[]) { MyAr m = new MyAr(); od(); } public void amethod() { Sln(i1); } } What is the output of the program?" MCQ Compilation Error Garbage Value It is not possible to access a static variable in side of non static method 1 0 0 0 "What will be printed out if you attempt to compile and run the following code ? public class AA { public static void main(String[] args) { int i = 9; switch (i) { default: Sln(""default""); case 0: Sln(""zero""); break; case 1: Sln(""one""); case 2: Sln(""two""); } } }" MCQ Compilation Error default default zero default zero one two 0 0 1 0 "Which statements, when inserted at (1), will not result in compile-time errors? public class ThisUsage { int planets; static int suns; public void gaze() { int i; // (1) INSERT STATEMENT HERE } }" MCA i = ts; i = ; this = new ThisUsage(); this.i = 4; = planets; 0.33 0.33 0 0 0.33 Which modifier is used to control access to critical code in multi-threaded programs? MCQ default public transient synchronized 0 0 0 1 "Given: package QB; class Meal { Meal() { Sln(""Meal()""); } } class Cheese { Cheese() { Sln(""Cheese()""); } } class Lunch extends Meal { Lunch() { Sln(""Lunch()""); } } class PortableLunch extends Lunch { PortableLunch() { Sln(""PortableLunch()""); } } class Sandwich extends PortableLunch { private Cheese c = new Cheese(); public Sandwich() { Sln(""Sandwich()""); } } public class MyClass7 { public static void main(String[] args) { new Sandwich(); } } What would be the output?" MCQ Meal() Lunch() PortableLunch() Cheese() Sandwich() Meal() Cheese() Lunch() PortableLunch() Sandwich() Meal() Lunch() PortableLunch() Sandwich() Cheese() Cheese() Sandwich() Meal() Lunch() PortableLunch() 1 0 0 0 "Consider the following code and choose the correct option: class A{ int a; A(int a){a=4;}} class B extends A{ B(){super(3);} void displayA(){ S(a);} public static void main(String args[]){ new B().displayA();}}" MCQ compiles and display 0 compilation error Compiles and display 4 Compiles and display 3 1 0 0 0 "Given the following code what will be output? public class Pass{ static int j=20; public static void main(String argv[]){ int i=10; Pass p = new Pass(); od(i); Sln(i); Sln(j); } public void amethod(int x){ x=x*2; j=j*2; } }" MCQ Error: amethod parameter does not match variable 20 and 40 10 and 40 10, and 20 0 0 1 0 What will happen if a main() method of a "testing" class tries to access a private instance variable of an object using dot notation? MCQ The compiler will automatically change the private variable to a public variable The compiler will find the error and will not make a .class file The program will compile and run successfully The program will compile successfully, but the .class file will not run correctly 0 1 0 0 "11. class Mud { 12. // insert code here 13. Sln(""hi""); 14. } 15. } And the following five fragments: public static void main(String...a) { public static void main(String.* a) { public static void main(String... a) { public static void main(String[]... a) { public static void main(String...[] a) { How many of the code fragments, inserted independently at line 12, compile?" MCQ 1 2 3 0 0 0 1 "class Order{ Order(){ Sln(""Cat""); } public static void main(String... Args){ Order obj = new Order(); Sln(""Ant""); } static{ Sln(""Dog""); } { Sln(""Man""); }} consider the code above & select the proper output from the options." MCQ Man Dog Cat Ant Cat Ant Dog Man Dog Man Cat Ant compile error 0 0 1 0 "abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i h;i++) Sln(ar[i]); } }" MCQ A Sequence of 5 zero's will be printed like 0 0 0 0 0 A Sequence of 5 one's will be printed like 1 1 1 1 1 IndexOutOfBoundes Error Compilation Error occurs and to avoid them we need to declare Mine class as abstract 0 0 0 1 "public class Q { public static void main(String argv[]) { int anar[] = new int[] { 1, 2, 3 }; Sln(anar[1]); } }" MCQ Compiler Error: anar is referenced before it is initialized 2 1 Compiler Error: size of array must be defined 0 1 0 0 A constructor may return value including class type MCQ true false 0 1 "Consider the following code and choose the correct option: package aj; class S{ int roll =23; private S(){} } package aj; class T { public static void main(String ar[]){ S(new S().roll);}}" MCQ Compilation error Compiles and display 0 Compiles and display 23 Compiles but no output 1 0 0 0 "public class c123 { private c123() { Sln(""Hellow""); } public static void main(String args[]) { c123 o1 = new c123(); c213 o2 = new c213(); } } class c213 { private c213() { Sln(""Hello123""); } } What is the output?" MCQ Hellow It is not possible to declare a constructor as private Compilation Error Runs without any output 0 0 1 0 "class MyClass1 { private int area(int side) { return(side * side); } public static void main(String args[ ]) { MyClass1 MC = new MyClass1( ); int area = MC.area(50); Sln(area); } } What would be the output?" MCQ Compilation error Runtime Exception 2500 50 0 0 1 0 "public class MyAr { public static void main(String argv[]) { MyAr m = new MyAr(); od(); } public void amethod() { static int i1; Sln(i1); } } What is the Output of the Program?" MCQ Compile time error because i has not been initialized Compilation and output of null It is not possible to declare a static variable in side of non static method or instance method. Because Static variables are class level dependencies. 0 0 0 1 "public class MyAr { public static void main(String argv[]) { MyAr m = new MyAr(); od(); } public void amethod() { final int i1; Sln(i1); } } What is the Output of the Program?" MCQ Unresolved compilation problem: The local variable i1 may not have been initialized Compilation and output of null None of the given options 0 1 0 0 "public class c1 { private c1() { Sln(""Hello""); } public static void main(String args[]) { c1 o1=new c1(); } } What is the output?" MCQ Hello It is not possible to declare a constructor private Compilation Error Can't create object because constructor is private 1 0 0 0 Which modifier indicates that the variable might be modified asynchronously, so that all threads will get the correct value of the variable. MCQ synchronized volatile transient default 0 1 0 0 "class A { int i, j; A(int a, int b) { i = a; j = b; } void show() { Sln(""i and j: "" + i + "" "" + j); } } class B extends A { int k; B(int a, int b, int c) { super(a, b); k = c; } void show(String msg) { Sln(msg + k); } } class Override { public static void main(String args[]) { B subOb = new B(3, 5, 7); subO(""This is k: ""); // this calls show() in B subO(); // this calls show() in A } } What would be the ouput?" MCQ This is j: 5 i and k: 3 7 This is i: 3 j and k: 5 7 This is i: 7 j and k: 3 5 This is k: 7 i and j: 3 7 0 0 0 1 "Consider the following code and choose the correct option: class X { int x; X(int x){x=2;}} class Y extends X{ Y(){} void displayX(){ S(x);} public static void main(String args[]){ new Y().displayX();}}" MCQ Compiles and display 2 Compiles and runs without any output Compiles and display 0 Compilation error 0 0 0 1 "class Order{ Order(){ Sln(""Cat""); } public static void main(String... Args){ Order obj = new Order(); Sln(""Ant""); } static{ Sln(""Dog""); }} consider the code above & select the proper output from the options." MCQ Cat Ant Dog Dog Cat Ant Ant Cat Dog none 0 1 0 0 "What will be the result when you attempt to compile this program? public class Rand{ public static void main(String argv[]){ int iRand; iRand = Mm(); Sln(iRand); } }" MCQ Compile time error referring to a cast problem A random number between 1 and 10 A random number between 0 and 1 A compile time error as random being an undefined method 1 0 0 0 Choose the meta annotations. (Choose THREE) MCA Override Retention Depricated Documented Target 0 0. 0 0. 0. If no retention policy is specified for an annotation, then the default policy of __________ is used. MCQ method class source runtime 0 1 0 0 Select the variable which are in ation.RetentionPolicy class. (Choose THREE) MCA SOURCE METHOD RUNTIME CONSTRUCTOR CLASS 0. 0 0. 0 0. Select the Uses of annotations. (Choose THREE) MCA Information For the Compiler Information for the JVM Compile time and deploytime processing Runtime processing Information for the OS 0. 0 0. 0. 0 All annotation types should maually extend the Annotation interface. State TRUE/FALSE MCQ true false 0 1 Custom annotations can be created using MCQ @interface @inherit @include all the listed options 1 0 0 0 "Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public void y() { } } 12. class C extends B { public void x() {} } And: 20. .Lista list = new .ArrayList/a(); 21. (new B()); 22. (new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?" MCQ Compilation fails because of an error in line 25 The code runs with no output. An exception is thrown at runtime Compilation fails because of an error in line 21 Compilation fails because of an error in line 23. 1 0 0 0 0 "Given: public static Collection get() { Collection sorted = new LinkedList(); (""B""); (""C""); (""A""); return sorted; } public static void main(String[] args) { for (Object obj: get()) { S(obj + "", ""); } } What is the result?" MCQ A, B, C, B, C, A, Compilation fails. An exception is thrown at runtime. 0 1 0 0 "Which statement is true about the following program? import .ArrayList; import .Collections; import .List; public class WhatISThis { public static void main(String[] na){ ListStringBuilder list=new ArrayListStringBuilder(); (new StringBuilder(""B"")); (new StringBuilder(""A"")); (new StringBuilder(""C"")); C(list,CseOrder()); Sln(List(1,2)); } }" MCQ The program will compile and print the following output: [B] The program will compile and print the following output: [B,A] The program will compile and throw a runtime exception The program will not compile 0 0 1 0 "Consider the following code and choose the correct option: public static void before() { Set set = new TreeSet(); (""2""); (3); (""1""); Iterator it = tor(); while (Next()) S(() + "" ""); }" MCQ The before() method will print 1 2 The before() method will print 1 2 3 The before() method will throw an exception at runtime The before() method will not compile 0 0 1 0 "import .StringTokenizer; class ST{ public static void main(String[] args){ String input = ""Today is$Holiday""; StringTokenizer st = new StringTokenizer(input,""$""); while(MoreTokens()){ Sln(Element()); }}" MCQ Today is Holiday Today is Holiday Both none of the listed options 0 1 0 0 "Given: public static Iterator reverse(List list) { Cse(list); return tor(); } public static void main(String[] args) { List list = new ArrayList(); (""1""); (""2""); (""3""); for (Object obj: reverse(list)) S(obj + "", ""); } What is the result?" MCQ 3, 2, 1, 1, 2, 3, Compilation fails. The code runs with no output. 0 0 1 0 "Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but its methods are not synchronized?" MCQ .HashSet .LinkedHashSet .List .ArrayList .Vector 0 0 0 1 0 int indexOf(Object o) - What does this method return if the element is not found in the List? MCQ null -1 none of the listed options 0 1 0 0 "What is the result of attempting to compile and run the following code? import .Vector; import .LinkedList; public class Test1{ public static void main(String[] args) { Integer int1 = new Integer(10); Vector vec1 = new Vector(); LinkedList list = new LinkedList(); (int1); (int1); if(s(list)) Sln(""equal""); else Sln(""not equal""); } } 1. The code will fail to compile. 2. Runtime error due to incompatible object comparison 3. Will run and print ""equal"". 4. Will run and print ""not equal""." MCQ 1 2 3 4 0 0 1 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Integer arr[]={3,4,3,2}; SetInteger s=new TreeSetInteger(AList(arr)); (1); for(Integer ele :s){ Sln(ele); } }}" MCQ Compilation error prints 3,4,2,1, prints 1,2,3,4 Compiles but exception at runtime 0 0 1 0 "Inorder to remove one element from the given Treeset, place the appropriate line of code public class Main { public static void main(String[] args) { TreeSetInteger tSet = new TreeSetInteger(); Sln(""Size of TreeSet : "" + tS()); tS(new Integer(""1"")); tS(new Integer(""2"")); tS(new Integer(""3"")); Sln(tS()); // remove the one element from the Treeset Sln(""Size of TreeSet after removal : "" + tS()); } }" MCQ tS(new Integer("1")); tSetdelete(new Integer("1")); tSe(new Integer("1")); tS(new Integer("1")); 0 0 1 0 "Consider the code below & select the correct ouput from the options: public class Test{ public static void main(String[] args) { String []colors={""orange"",""blue"",""red"",""green"",""ivory""}; A(colors); int s1=AySearch(colors, ""ivory""); int s2=AySearch(colors, ""silver""); Sln(s1+"" ""+s2); }}" MCQ 2 -4 3 -5 2 -6 3 -4 0 0 1 0 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ TreeMapInteger, String hm=new TreeMapInteger, String(); (2,""Two""); (4,""Four""); (1,""One""); (6,""Six""); (7,""Seven""); SortedMapInteger, String sm=Map(2,7); SortedMapInteger,String sm2=Map(4); S(sm2); }}" MCQ {2=Two, 4=Four, 6=Six, 7=Seven} {4=Four, 6=Six, 7=Seven} {4=Four, 6=Six} {2=Two, 4=Four, 6=Six} 0 0 1 0 next() method of Scanner class will return _________ MCQ Integer Long int String 0 0 0 1 "Given: import .Arrays; import .HashSet; import .Set; public class MainClass { public static void main(String[] a) { String elements[] = { ""A"", ""B"", ""C"", ""D"", ""E"" }; Set set = new HashSet(AList(elements)); elements = new String[] { ""A"", ""B"", ""C"", ""D"" }; Set set2 = new HashSet(AList(elements)); Sln(s(set2)); } } What is the result of given code?" MCQ true false Compile time error Runtime Exception 0 1 0 0 "A)Property files help to decrease coupling B) DateFormat class allows you to format dates and times with customized styles. C) Calendar class allows to perform date calculation and conversion of dates and times between timezones. D) Vector class is not synchronized" MCQ A and B is TRUE A and D is TRUE A and C is TRUE B and D is TRUE 0 0 1 0 Which interface does .Hashtable implement? MCQ J.Map J.List J.Table J.Collection 1 0 0 0 Object get(Object key) - What does this method return if the key is not found in the Map? MCQ -1 null none of the listed options 0 0 1 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ TreeSetInteger ts=new TreeSetInteger(); (1); (8); (6); (4); SortedSetInteger ss=Set(2, 10); (9); Sln(ts); Sln(ss); }}" MCQ [1,4,6,8] [4,6,8,9] [1,8,6,4] [8,6,4,9] [1,4,6,8,9] [4,6,8,9] [1,4,6,8,9] [4,6,8] 0 0 1 0 "A) Iterator does not allow to insert elements during traversal B) Iterator allows bidirectional navigation. C) ListIterator allows insertion of elements during traversal D) ListIterator does not support bidirectional navigation" MCQ A and B is TRUE A and D is TRUE A and C is TRUE B and D is TRUE 0 0 1 0 static void sort(List list) method is part of ________ MCQ Collection interface Collections class Vector class ArrayList class 0 1 0 0 static int binarySearch(List list, Object key) is a method of __________ MCQ Vector class ArrayList class Collection interface Collections class 0 0 0 1 Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization? MCQ .SortedMap .TreeMap .TreeSet .Hashtable 0 0 0 1 "Consider the following code and select the correct output: import .ArrayList; import .LinkedList; import .List; public class Lists { public static void main(String[] args) { ListString list=new ArrayListString(); (""1""); (""2""); (1, ""3""); ListString list2=new LinkedListString(list); All(list2); list2 =List(2,5); (); Sln(list); } }" MCQ [1,3,2] [1,3,3,2] [1,3,2,1,3,2] [3,1,2] [3,1,1,2] 1 0 0 0 0 "Given: import .*; public class LetterASort{ public static void main(String[] args) { ArrayListString strings = new ArrayListString(); (""aAaA""); (""AaA""); (""aAa""); (""AAaa""); C(strings); for (String s : strings) { S(s + "" ""); } } } What is the result?" MCQ Compilation fails. aAaA aAa AAaa AaA AAaa AaA aAa aAaA AaA AAaa aAaA aAa 0 0 1 0 "A) It is a good practice to store heterogenous data in a TreeSet. B) HashSet has default initial capacity (16) and loadfactor(0.75) C)HashSet does not maintain order of Insertion D)TreeSet maintains order of Inserstion" MCQ A and B is TRUE A and D is TRUE A and C is TRUE B and C is TRUE 0 0 0 1 "TreeSetString s = new TreeSetString(); TreeSetString subs = new TreeSetString(); (""a""); (""b""); (""c""); (""d""); (""e""); subs = (TreeSet)Set(""b"", true, ""d"", true); (""g""); First(); First(); (""c2""); Sln(() +"" ""+ ());" MCA The size of s is 4 The size of s is 5 The size of subs is 3 The size of s is 7 The size of subs is 1 0 0.5 0.5 0 0 "Consider the following code was executed on June 01, 1983. What will be the output? class Test{ public static void main(String args[]){ Date date=new Date(); SimpleDateFormat sd; sd=new SimplpeDateFormat(""E MMM dd yyyy""); S(t(date));}}" MCQ Wed Jun 01 1983 244 JUN 01 1983 PST JUN 01 1983 GMT JUN 01 1983 1 0 0 0 "Given: public class Venus { public static void main(String[] args) { int [] x = {1,2,3}; int y[] = {4,5,6}; new Venus().go(x,y); } void go(int[]... z) { for(int[] a : z) S(a[0]); } } What is the result?" MCQ 123 12 14 1 0 0 1 0 "You wish to store a small amount of data and make it available for rapid access. You do not have a need for the data to be sorted, uniqueness is not an issue and the data will remain fairly static Which data structure might be most suitable for this requirement? 1) TreeSet 2) HashMap 3) LinkedList 4) an array" MCQ 1 2 3 4 0 0 0 1 "What will be the output of following code? class Test{ public static void main(String args[]){ TreeSetInteger ts=new TreeSetInteger(); (2); (3); (7); (5); SortedSetInteger ss=Set(1,7); (4); (6); S(ss);}}" MCQ [2,3,7,5] [2,3,7,5,4,6] [2,3,4,5,6,7] [2,3,4,5,6] 0 0 0 1 "Consider the following code and choose the correct option: class Data{ Integer data; Data(Integer d){data=d;} public boolean equals(Object o){return true;} public int hasCode(){return 1;}} class Test{ public static void main(String ar[]){ SetData s=new HashSetData(); (new Data(4)); (new Data(2)); (new Data(4)); (new Data(1)); (new Data(2)); S(());}}" MCQ 3 5 compilation error Compiles but error at run time 0 1 0 0 "Consider the code below & select the correct ouput from the options: public class Test{ public static void main(String[] args) { String num=""""; z: for(int x=0;x3;x++) for(int y=0;y2;y++){ if(x==1) break; if(x==2 && y==1) break z; num=num+x+y; }Sln(num);}}" MCQ 0001 Compilation error 0 1 0 0 "Given: public class Test { public enum Dogs {collie, harrier}; public static void main(String [] args) { Dogs myDog = De; switch (myDog) { case collie: S(""collie ""); case harrier: S(""harrier ""); } } } What is the result?" MCQ collie harrier Compilation fails. collie harrier 0 0 0 1 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ boolean flag=true; if(flag=false){ S(""TRUE"");}else{ S(""FALSE"");}}}" MCQ true false compilation error Compiles 0 1 0 0 "Cosider the following code and choose the correct option: class Test{ public static void main(String args[]){ Sln(IInt(""8"", 10)); }}" MCQ Compilation error 2.E9 NumberFormatException at run time Compiles but no output 0 0 1 0 "Given: public class Test { public enum Dogs {collie, harrier, shepherd}; public static void main(String [] args) { Dogs myDog = Derd; switch (myDog) { case collie: S(""collie ""); case default: S(""retriever ""); case harrier: S(""harrier ""); } } } What is the result?" MCQ harrier shepherd retriever Compilation fails. 0 0 0 1 "Given: static void myFunc() { int i, s = 0; for (int j = 0; j 7; j++) { i = 0; do { i++; s++; } while (i j); } Sln(s); } } What would be the result" MCQ 20 21 22 23 24 0 0 1 0 0 "What is the range of the random number r generated by the code below? int r = (int)(M(Mm() * 8)) + 2;" MCQ 2 = r = 9 3 = r = 10 2= r = 10 3 = r = 9 1 0 0 0 "class Test{ public static void main(String[] args) { int x=-1,y=-1; if(++x=++y) Sln(""R.T. Ponting""); else Sln(""C.H. Gayle""); } } consider the code above & select the proper output from the options." MCQ R.T.Ponting C.H.Gayle Compile error none of the listed options 0 0 1 0 "Given: public class Breaker2 { static String o = """"; public static void main(String[] args) { z: for(int x = 2; x 7; x++) { if(x==3) continue; if(x==5) break z; o = o + x; } Sln(o); } } What is the result?" MCQ 2 24 234 246 0 1 0 0 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int a=5; if(a=3){ S(""Three"");}else{ S(""Five"");}}}" MCQ Compilation error Three Five Compiles but no output 1 0 0 0 "Given: public class Batman { int squares = 81; public static void main(String[] args) { new Batman().go(); } void go() { incr(++squares); Sln(squares); } void incr(int squares) { squares += 10; } } What is the result?" MCQ 81 82 91 92 0 1 0 0 "public void foo( boolean a, boolean b) { if( a ) { Sln(""A""); /* Line 5 */ } else if(a && b) /* Line 7 */ { Sln( ""A && B""); } else /* Line 11 */ { if ( !b ) { Sln( ""notB"") ; } else { Sln( ""ELSE"" ) ; } } } What would be the result?" MCQ If a is true and b is false then the output is "notB" If a is true and b is true then the output is "A && B" If a is false and b is false then the output is "ELSE" If a is false and b is true then the output is "ELSE" 0 0 0 1 "What is the value of ’n’ after executing the following code? int n = 10; int p = n + 5; int q = p - 10; int r = 2 * (p - q); switch(n) { case p: n = n + 1; case q: n = n + 2; case r: n = n + 3; default: n = n + 4; }" MCQ 14 28 Compilation Error 10 Runtime Error 0 0 1 0 0 "public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { S(""x plus one is "" + (x + 1)); /* Line 8 */ } } } Which statement is true?" MCQ 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 0 0 0 1 "Which of the following loop bodies DOES compute the product from 1 to 10 like (1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10)? int s = 1; for (int i = 1; i = 10; i++) { What to put here? }" MCQ s += i * i; s++; s = s + s * i; s *= i; Compilation error 0 0 0 1 0 Which of the following statements are true regarding wrapper classes? (Choose TWO) MCA String is a wrapper class Double has a compareTo() method Character has a intValue() method Byte extends Number String is the wrapper class of char 0 0.5 0 0.5 0 "Given: class Atom { Atom() { S(""atom ""); } } class Rock extends Atom { Rock(String type) { S(type); } } public class Mountain extends Rock { Mountain() { super(""granite ""); new Rock(""granite ""); } public static void main(String[] a) { new Mountain(); } } What is the result?" MCQ Compilation fails. granite granite atom granite granite atom granite atom granite 0 0 0 1 "What are the thing to be placed to complete the code? class Wrap { public static void main(String args[]) { _______________ iOb = ___________ Integer(100); int i = iOValue(); Sln(i + "" "" + iOb); // displays 100 100 } }" MCQ int, int Integer, new Integer, int int, Integer 0 1 0 0 "public class SwitchTest { public static void main(String[] args) { Sln(""value ="" + switchIt(4)); } public static int switchIt(int x) { int j = 1; switch (x) { case 1: j++; case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++; } return j + x; } } What will be the output of the program?" MCQ value = 8 value = 2 value = 4 value = 6 1 0 0 0 "Given: public class Barn { public static void main(String[] args) { new Barn().go(""hi"", 1); new Barn().go(""hi"", ""world"", 2); } public void go(String... y, int x) { S(y[h - 1] + "" ""); } } What is the result?" MCQ hi hi hi world world world Compilation fails. 0 0 0 1 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ int x=034; int y=12; int ans=x+y; Sln(ans); }}" MCQ 40 46 compilation error Compiles but error at run time 1 0 0 0 "11. double input = .26; 12. NumberFormat nf = NumberFInstance(Locale.ITALIAN); 13. String b; 14. //insert code here Which code, inserted at line 14, sets the value of b to 314.159,26?" MCQ b = ( input ); b = t( input ); b = s( input ); b = Object( input ); 0 1 0 0 "Consider the following code and choose the correct option: class Test{ public static void main(String ar[]){ TreeMapInteger,String tree = new TreeMapInteger,String(); (1, ""one""); (2, ""two""); (3, ""three""); (4,""Four""); Sln(rKey(2)); Sln(ngKey(2)); Sln(Key(1)); Sln(Key(1)); }}" MCQ 3 2 1 null 3 2 1 1 2 2 1 1 4 2 1 1 1 0 0 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long data=23; Sln(data); }}" MCQ 23 Compilation error Compiles but error at run time None of the listed options 0 1 0 0 "class AutoBox { public static void main(String args[]) { int i = 10; Integer iOb = 100; i = iOb; Sln(i + "" "" + iOb); } } whether this code work properly, if so what would be the result?" MCQ No, Compilation error No, Runtime error Yes, 10, 100 Yes, 100, 100 0 0 0 1 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long l=0l; Sln(s(0));}}" MCQ Compilation error true false 1 0 0 1 0 "int I = 0; outer: while (true) { I++; inner: for (int j = 0; j 10; j++) { I += j; if (j == 3) continue inner; break outer; } continue outer; } Sln(I); What will be thr result?" MCQ 3 2 4 1 0 0 0 1 "what will be the result of attempting to compile and run the following class? Public class IFTest{ public static void main(String[] args){ int i=10; if(i==10) if(i10) Sln(""a""); else Sln(""b""); }}" MCQ The code will fail to compile because the syntax of the if statement is incorrect The code will fail to compile because the compiler will not be able to determine which if statement the else clause belongs to The code will compile correctly and display the letter a,when run The code will compile correctly and display the letter b,when run The code will compile correctly,but will not display any output 0 0 0 1 0 "What is the output of the following code : class try1{ public static void main(String[] args) { Sln(""good""); while(false){ Sln(""morning""); } } }" MCQ good good morning morning …. compiler error runtime error 0 0 1 0 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num=3; switch(num){ case 1: case 3: case 4: { Sln(""bat man""); } case 2: case 5: { Sln(""spider man""); }break; } }}" MCQ bat man Compilation error bat man spider man spider man 0 0 1 0 "Given: int n = 10; switch(n) { case 10: n = n + 1; case 15: n = n + 2; case 20: n = n + 3; case 25: n = n + 4; case 30: n = n + 5; } Sln(n); What is the value of ’n’ after executing the following code?" MCQ 23 32 25 Compilation Error Runtine Error 0 0 1 0 0 "What will be the output of following code? TreeSet map = new TreeSet(); (""one""); (""two""); (""three""); (""four""); (""one""); Iterator it = tor(); while (Next() ) { S( () + "" "" ); }" MCQ one two three four four three two one four one three two one two three four one 0 0 1 0 "public class Test { public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) S(""1 ""); S(""2 ""); if ((b2 = true) && b1 ) S(""3 ""); } } What is the result?" MCQ 2 3 2 3 1 2 3 0 0 1 0 Which of these statements are true? MCA HashTable is a sub class of Dictionary ArrayList is a sub class of Vector LinkedList is a subclass of ArrayList Stack is a subclass of Vector 0.5 0 0 0.5 "Given: import .*; public class Explorer3 { public static void main(String[] args) { TreeSetInteger s = new TreeSetInteger(); TreeSetInteger subs = new TreeSetInteger(); for(int i = 606; i 613; i++) if(i%2 == 0) (i); subs = (TreeSet)Set(608, true, 611, true); (629); Sln(s + "" "" + subs); } } What is the result?" MCQ Compilation fails. [608, 610, 612, 629] [608, 610] An exception is thrown at runtime. [608, 610, 612, 629] [608, 610, 629] 0 0 1 0 "What is the output : class try1{ public static void main(String[] args) { int x=1; if(x--) Sln(""good""); else Sln(""bad""); } }" MCQ good bad compile error run time error 0 0 1 0 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num='b'; switch(num){ default :{ S(""default"");} case 100 : case 'b' : case 'c' : { Sln(""brownie""); break;} case 200: case 'e': { Sln(""pastry""); }break; } }}" MCQ brownie default brownie compilation error default 1 0 0 0 "Given: int a = 5; int b = 5; int c = 5; if (a 3) if (b 4) if (c 5) c += 1; else c += 2; else c += 3; c += 4; What is the value of variable c after executing the following code?" MCQ 3 5 7 9 11 0 0 0 0 1 "Given: Float pi = new Float(3.14f); if (pi 3) { S(""pi is bigger than 3. ""); } else { S(""pi is not bigger than 3. ""); } finally { Sln(""Have a nice day.""); } What is the result?" MCQ Compilation fails. pi is bigger than 3. An exception occurs at runtime. pi is bigger than 3. Have a nice day. 1 0 0 0 "Given: public void go() { String o = """"; z: for(int x = 0; x 3; x++) { for(int y = 0; y 2; y++) { if(x==1) break; if(x==2 && y==1) break z; o = o + x + y; } } Sln(o); } What is the result when the go() method is invoked?" MCQ 00 0001 0 0 1 0 "Examine the following code: int count = 1; while ( ___________ ) { S( count + "" "" ); count = count + 1; } Sln( ); What condition should be used so that the code prints: 1 2 3 4 5 6 7 8" MCQ count 9 count+1 = 8 count 8 count != 8 1 0 0 0 "What will be the output of the program? public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z 3; z++) { switch (z) { case y: S(""0 ""); /* Line 11 */ case x-1: S(""1 ""); /* Line 12 */ case x: S(""2 ""); /* Line 13 */ } } } }" MCQ 0 1 2 0 1 2 1 2 2 Compilation fails at line 11 Compilation fails at line 12. 0 0 1 0 "Given: int x = 0; int y = 10; do { y--; ++x; } while (x 5); S(x + "","" + y); What is the result?" MCQ 5,6 5,5 6,5 6,6 0 1 0 0 "What is the output : class Test{ public static void main(String[] args) { int a=5,b=10,c=1; if(ac){ Sln(""success""); } else{ break; } } }" MCQ success runtime error compiler error none of the listed options 0 0 1 0 "Consider the following code and choose the correct output: public class Test{ public static void main(String[] args) { int x = 0; int y = 10; do { y--; ++x; } while (x 5); S(x + "","" + y); } }" MCQ 5,6 5,5 6,5 6,6 0 1 0 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ int l=7; Long L = (Long)l; Sln(L); }}" MCQ 7 Compilation error Compiles but error at run time None of the listed options 0 1 0 0 "Given: double height = 5.5; if(height-- = 5.0) S(""tall ""); if(--height = 4.0) S(""average ""); if(height-- = 3.0) S(""short ""); else S(""very short ""); } What would be the Result?" MCQ tall tall short short very short average 0 1 0 0 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ String hexa = ""0XFF""; int number = Ie(hexa); Sln(number); }}" MCQ Compilation error 1515 255 Compiles but error at run time 0 0 1 0 "Consider the following code and choose the correct option: int i = l, j = -1; switch (i) { case 0, 1: j = 1; case 2: j = 2; default: j = 0; } Sln(""j = "" + j);" MCQ j = -1 j = 0 j = 1 Compilation fails 0 0 0 1 Which of the following statements about arrays is syntactically wrong? MCQ Person[] p = new Person[5]; Person p[5]; Person[] p []; Person p[][] = new Person[2][]; 0 1 0 0 "What will be the output of following code? import .*; class I { public static void main (String[] args) { Object i = new ArrayList().iterator(); S((i instanceof List)+"",""); S((i instanceof Iterator)+"",""); S(i instanceof ListIterator); } }" MCQ Prints: false, false, false Prints: false, false, true Prints: false, true, false Prints: false, true, true 0 0 1 0 "Given: public static void test(String str) { int check = 4; if (check = h()) { S(At(check -= 1) +"", ""); } else { S(At(0) + "", ""); } } and the invocation: test(""four""); test(""tee""); test(""to""); What is the result?" MCQ r, t, t, r, e, o, Compilation fails. An exception is thrown at runtime. 0 0 1 0 "What will be the output of the program? int x = 3; int y = 1; if (x = y) /* Line 3 */ { Sln(""x ="" + x); }" MCQ x = 1 x = 3 Compilation fails. The code runs with no output. 0 0 1 0 "import .SortedSet; import .TreeSet; public class Main { public static void main(String[] args) { TreeSetString tSet = new TreeSetString(); tS(""1""); tS(""2""); tS(""3""); tS(""4""); tS(""5""); SortedSet sortedSet =_____________(""3""); Sln(""Head Set Contains : "" + sortedSet); } } What is the missing method in the code to get the head set of the tree set?" MCQ tSSet et headSet HeadSet 1 0 0 0 "Consider the following code and choose the correct output: class Test{ public static void main(String args[]){ int num=3; switch(num){ default :{ S(""default"");} case 1: case 3: case 4: { Sln(""apple""); break;} case 2: case 5: { Sln(""black berry""); }break; } }}" MCQ apple default apple compilation error default 1 0 0 0 "Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long L = null; long l = L; Sln(L); Sln(l); }}" MCQ null 0 Compilation error Compiles but error at run time 0 null 0 0 1 0 "What does the following code fragment write to the monitor? int sum = 21; if ( sum != 20 ) S(""You win ""); else S(""You lose ""); Sln(""the prize.""); What does the code fragment prints?" MCQ You win the prize You lose the prize. You win You lose 1 0 0 0 Which statements are true about maps? (Choose TWO) MCA The return type of the values() method is set Changes made in the Set view returned by keySet() will be reflected in the original map The Map interface extends the Collection interface All keys in a map are unique All Map implementations keep the keys sorted 0 0.5 0 0.5 0 Which collection implementation is suitable for maintaining an ordered sequence of objects,when objects are frequently inserted in and removed from the middle of the sequence? MCQ TreeMap HashSet Vector LinkedList ArrayList 0 0 0 1 0 Choose TWO correct options: MCA OutputStream is the abstract superclass of all classes that represent an outputstream of bytes. Subclasses of the class Reader are used to read character streams. To write characters to an outputstream, you have to make use of the class CharacterOutputStream. To write an object to a file, you use the class ObjectFileWriter 0.5 0.5 0 0 "What is the output : class One{ public static void main(String[] args) { int a=100; if(a10) Sln(""M.S.Dhoni""); else if(a20) Sln(""Sachin""); else if(a30) Sln(""Virat Kohli"");} }" MCQ M.S.Dhoni M.S.Dhoni Sachin Virat Kohli Virat Kohli all of these 1 0 0 0 Which of the following statements is TRUE regarding a Java loop? MCQ A continue statement doesn’t transfer control to the test statement of the for loop An overflow error can only occur in a loop A loop may have multiple exit points If a variable of type int overflows during the execution of a loop, it will cause an exception 0 0 1 0 "switch(x) { default: Sln(""Hello""); } Which of the following are acceptable types for x? 5.Short 6.Long" MCQ 1 ,3 and 5 2 and 4 3 and 5 4 and 6 1 0 0 0 Which are true with respect to finally block? (Choose THREE) MCA Used to release the resources which are obtained in try block. Writing finally block is optional. When an exception occurs then a part of try block will execute one appropriate catch block and finally block will be executed. finally block will never execute when no exceptions are there. When no exception occurs then complete try block and finally block will execute but no catch block will execute. 0.25 0.25 0.25 0 0.25 "What will happen when you attempt to compile and run the following code? public class Bground extends Thread{ public static void main(String argv[]){ Bground b = new Bground(); (); } public void start(){ for (int i = 0; i 10; i++){ Sln(""Value of i = "" + i); } } }" MCQ A compile time error indicating that no run method is defined for the Thread class A run time error indicating that no run method is defined for the Thread class Clean compile and at run time the values 0 to 9 are printed out Clean compile but no output at runtime 0 0 0 1 "Given: public void testIfA() { if (testIfB(""True"")) { Sln(""True""); } else { Sln(""Not true""); } } public Boolean testIfB(String str) { return BOf(str); } What is the result when method testIfA is invoked?" MCQ true Not true An exception is thrown at runtime. none 1 0 0 0 Which of the following statements are true? (Choose TWO) MCA Deadlock will not occur if wait()/notify() is used The wait() method is overloaded to accept a duration A thread will resume execution as soon as its sleep duration expires. The notify() method is overloaded to accept a duration Both wait() and notify() must be called from a synchronized context. 0 0.33 0.33 0 0.33 "public class MyProgram { public static void throwit() { throw new RuntimeException(); } public static void main(String args[]) { try { Sln(""Hello world ""); throwit(); Sln(""Done with try block ""); } finally { Sln(""Finally executing ""); } } } which answer most closely indicates the behavior of the program?" MCQ The program will not compile. The program will print Hello world, then will print that a RuntimeException has occurred, then will print Done with try block, and then will print Finally executing. The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing. The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred. 0 0 0 1 If a method is capable of causing an exception that it does not handle, it must specify this behavior using throws so that callers of the method can guard themselves against such Exception MCQ false true 0 1 "A) Checked Exception must be explicity caught or propagated to the calling method B) If runtime system can not find an appropriate method to handle the exception, then the runtime system terminates and uses the default exception handler." MCQ Only A is TRUE Only B is TRUE Bothe A and B is TRUE Both A and B is FALSE 0 0 1 0 "public class RTExcept { public static void throwit () { S(""throwit ""); throw new RuntimeException(); } public static void main(String [] args) { try { S(""hello ""); throwit(); } catch (Exception re ) { S(""caught ""); } finally { S(""finally ""); } Sln(""after ""); } }" MCQ hello throwit caught finally after hello throwit caught hello throwit RuntimeException caught after Compilation fails 1 0 0 0 "class s implements Runnable { int x, y; public void run() { for(int i = 0; i 1000; i++) synchronized(this) { x = 12; y = 12; } S(x + "" "" + y + "" ""); } public static void main(String args[]) { s run = new s(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); (); (); } } What is the output?" MCQ DeadLock Compilation Error Cannot determine output. prints 0 0 0 1 "What is wrong with the following code? Class MyException extends Exception{} public class Test{ public void foo() { try { bar(); } finally { baz(); } catch(MyException e) {} } public void bar() throws MyException { throw new MyException(); } public void baz() throws RuntimeException { throw new RuntimeException(); } }" MCQ Since the method foo() does not catch the exception generated by the method baz(),it must declare the RuntimeException in a throws clause A try block cannot be followed by both a catch and a finally block An empty catch block is not allowed A catch block cannot follow a finally block A finally block must always follow one or more catch blocks 0 0 0 1 0 "Consider the following code and choose the correct option: class Test{ static void test() throws RuntimeException { try { S(""test ""); throw new RuntimeException(); } catch (Exception ex) { S(""exception ""); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { S(""runtime ""); } S(""end""); } }" MCQ test end test runtime end test exception runtime end test exception end 0 0 0 1 Choose TWO correct options: MCA If an exception is not caught in a method,the method will terminate and normal execution will resume An overriding method must declare that it throws the same exception classes as the method it overrides The main() method of a program can declare that it throws checked exception A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class Finally blocks are executed if,an exception gets thrown while inside the corresponding try block 0 0 0.5 0.5 0 "Which four can be thrown using the throw statement? 1.Error 2.Event 3.Object 4.Throwable 5.Exception 6.RuntimeException" MCQ 1, 2, 3 and 4 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1 0 "class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } Which of the following line of code is suitable to start a thread ?" MCQ Thread t = new Thread(X); Thread t = new Thread(X); (); X run = new X(); Thread t = new Thread(run); (); Thread t = new Thread(); (); 0 0 1 0 "Given: class X { public void foo() { S(""X ""); } } public class SubB extends X { public void foo() throws RuntimeException { (); if (true) throw new RuntimeException(); S(""B ""); } public static void main(String[] args) { new SubB().foo(); } } What is the result?" MCQ X, followed by an Exception. No output, and an Exception is thrown. X, followed by an Exception, followed by B. none 1 0 0 0 "What will the output of following code? try { int x = 0; int y = 5 / x; } catch (Exception e) { Sln(""Exception""); } catch (ArithmeticException ae) { Sln("" Arithmetic Exception""); } Sln(""finished"");" MCQ finished Exception compilation fails ArithmeticException 0 0 1 0 Which of the following methods are static? MCA start() join() yield() sleep() 0 0 0.5 0.5 Which of the following statements regarding static methods are correct? (2 answers) MCA static methods are difficult to maintain, because you can not change their implementation. static methods can be called using an object reference to an object of the class in which this method is defined. static methods are always public, because they are defined at class-level. static methods do not have direct access to non-static methods which are defined inside the same class. 0 0.5 0 0.5 "Consider the following code and choose the correct option: class Test{ static void display(){ throw new RuntimeException(); } public static void main(String args[]){ try{display(); }catch(Exception e){ throw new NullPointerException();} finally{try{ display(); }catch(NullPointerException e){ Sln(""caught"");} finally{ Sln(""exit"");}}}}" MCQ caught exit exit exit RuntimeException thrown at run time Compilation fails 0 0 1 0 "class Test{ public static void main(String[] args){ try{ IInt(""1.0""); } catch(Exception e){ Sln(""Exception occurred""); } catch(RuntimeException ex){ Sln(""RuntimeException""); } } } consider the code above & select the proper output from the options." MCQ Exception occurred RuntimeException Exception occurred RuntimeException does not compile 0 0 0 1 "Which three of the following are methods of the Object class? y(); yAll(); Interrupted(); ronized(); rupt(); (long msecs); (long msecs); ();" MCQ 1, 2, 4 2, 4, 5 1, 2, 6 2, 3, 4 0 0 1 0 "In the given code snippet try { int a = IInt(""one""); } what is used to create an appropriate catch block? (Choose all that apply.) A. ClassCastException B. IllegalStateException C. NumberFormatException D. IllegalArgumentException" MCA ClassCastException NumberFormatException IllegalStateException IllegalArgumentException 0 0.5 0 0.5 "class Trial{ public static void main(String[] args){ try{ Sln(""One""); int y = 2 / 0; Sln(""Two""); } catch(RuntimeException ex){ Sln(""Catch""); } finally{ Sln(""Finally""); } } }" MCQ One Two Catch Finally One Catch One Catch Finally One Two Catch 0 0 1 0 "Which digit,and in what order,will be printed when the following program is run? Public class MyClass { public static void main(String[] args) { int k=0; try { int i=5/k; } catch(ArithmeticException e) { Sln(""1""); } catch(RuntimeException e) { Sln(""2""); return; } catch(Exception e) { Sln(""3""); } finally{ Sln(""4""); } Sln(""5""); } }" MCQ The program will only print 5 The program will only print 1 and 4 in order The program will only print 1,2 and 4 in order The program will only print 1 ,4 and 5 in order The program will only print 1,2,4 and 5 in order 0 0 0 1 0 "class Trial{ public static void main(String[] args){ try{ Sln(""Java is portable""); } } }" MCQ Java is portable We cannot have a try block without a catch


Información del documento

Subido en
24 de octubre de 2022
Número de páginas
309
Escrito en
2022/2023
Tipo
Examen
Contiene
Preguntas y respuestas
$20.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Madefamiliar
4.4
(201)
Vendido
1299
Seguidores
917
Artículos
3305
Última venta
2 meses hace


Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes

Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.