· 8 years ago · May 31, 2018, 07:06 PM
1
2Access Specifiers Constructors Methods NewQB
3What 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) }}
4MCQ
5A compilation error will occur at (Line no 1), since constructors cannot specify a return value
6A compilation error will occur at (2), since the class does not have a default constructor
7A compilation error will occur at (Line no 2), since the class does not have a constructor that takes one argument of type int.
8The program will compile without errors.
90
100
110
121
13Access Specifiers Constructors Methods NewQB
14Which of the following declarations are correct? (Choose TWO)
15MCA
16boolean b = TRUE;
17byte b = 256;
18String s = “nullâ€;
19int i = new Integer(“56â€);
200
210
220.5
230.5
24Access Specifiers Constructors Methods NewQB
25What will happen when you attempt to compile and run this code?abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }}public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My Func"); } public void amethod(){ myfunc(); }}
26MCQ
27The code will compile and run, printing out the words "My Func"
28The compiler will complain that the Base class has non abstract methods
29The code will compile but complain at run time that the Base class has non abstract methods
30The compiler will complain that the method myfunc in the base class has no body, nobody at all to print it
311
320
330
340
35Access Specifiers Constructors Methods NewQB
36class 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?
37MCQ
38Constructor of A executes first, followed by the constructor of B and C
39Constructor of C executes first followed by the constructor of A and B
40Constructor of C executes first followed by the constructor of B and A
41Constructor of A executes first followed by the constructor of C and B
421
430
440
450
46Access Specifiers Constructors Methods NewQB
47Consider 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[]){ System.out.print(new S().roll);}}
48MCQ
49Compilation error
50Compiles and display 1
51Compiles but no output
52Compiles and diplay 0
531
540
550
560
57Access Specifiers Constructors Methods NewQB
58Here is the general syntax for method definition: accessModifier returnType methodName( parameterList ){ Java statements return returnValue;}What is true for the returnType and the returnValue?
59MCQ
60The returnValue can be any type, but will be automatically converted to returnType when the method returns to the caller
61If the returnType is void then the returnValue can be any type
62The returnValue must be the same type as the returnType, or be of a type that can be converted to returnType without loss of information
63The returnValue must be exactly the same type as the returnType.
640
650
661
670
68Access Specifiers Constructors Methods NewQB
69A) 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.
70MCQ
71Both are FALSE
72Both are TRUE
73Only A is TRUE
74Only B is TRUE
750
761
770
780
79Access Specifiers Constructors Methods NewQB
80Consider the following code and choose the correct option:class A{ A(){System.out.print("From A");}}class B extends A{ B(int z){z=2;}public static void main(String args[]){ new B(3);}}
81MCQ
82Compilation error
83Comiples and prints From A
84Compiles but throws runtime exception
85Compiles and display 3
860
871
880
890
90Access Specifiers Constructors Methods NewQB
91class Sample{int a,b;Sample(){ a=1; b=2;System.out.println(a+"\t"+b);}Sample(int x){ this(10,20);a=b=x;System.out.println(a+"\t"+b);}Sample(int a,int b){ this();this.a=a;this.b=b;System.out.println(a+"\t"+b);}}class This2{ public static void main(String args[]){Sample s1=new Sample (100);}}What is the Output of the Program?
92MCQ
93100 100 1 2 10 20
941 2 100 100 10 20
9510 20 1 2 100 100
961 2 10 20 100 100
970
980
990
1001
101Access Specifiers Constructors Methods NewQB
102Consider the following code and choose the correct option:class A{ private static void display(){ System.out.print("Hi");}public static void main(String ar[]){display();}}
103MCQ
104Compiles and display Hi
105Compiles and throw run time exception
106Compiles but doesn't display anything
107Compilation fails
1081
1090
1100
1110
112Access Specifiers Constructors Methods NewQB
113Consider 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[]){ System.out.print(new A().j=23);}}
114MCQ
115code compiles fine and will display 23
116code compiles but will not display output
117compliation error
118j can not be initialized
1190
1200
1211
1220
123Access Specifiers Constructors Methods NewQB
124Consider 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();}}
125MCQ
126Compilation error
127Compiles but throws run time exception
128Compiles and displays nothing
129None of the listed options
1301
1310
1320
1330
134Access Specifiers Constructors Methods NewQB
135class Test{static void method(){this.display();}static display(){System.out.println(("hello");}public static void main(String[] args){new Test().method();}}consider the code above & select the proper output from the options.
136MCQ
137hello
138Runtime Error
139compiles but no output
140does not compile
1410
1420
1430
1441
145Access Specifiers Constructors Methods NewQB
146What will be the result when you try to compile and run the following code? private class Base{ Base(){ int i = 100; System.out.println(i); }}public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); }}
147MCQ
148200
149100 followed by 200
150Compile time error
151100
1520
1530
1541
1550
156Access Specifiers Constructors Methods NewQB
157public class MyClass { static void print(String s, int i) { System.out.println("String: " + s + ", int: " + i); } static void print(int i, String s) { System.out.println("int: " + i + ", String: " + s); } public static void main(String[] args) { print("String first", 11); print(99, "Int first"); }}What would be the output?
158MCQ
159String: String first, int: 11 int: 99, String: Int first
160int: 27, String: Int first String: String first, int: 27
161Compilation Error
162Runtime Exception
1631
1640
1650
1660
167Access Specifiers Constructors Methods NewQB
168A) No argument constructor is provided to all Java classes by defaultB) No argument constructor is provided to the class only when no constructor is defined.C) Constructor can have another class object as an argumentD) Access specifiers are not applicable to Constructor
169MCQ
170Only A is TRUE
171All are TRUE
172B and C is TRUE
173All are FALSE
1740
1750
1761
1770
178Access Specifiers Constructors Methods NewQB
179Consider the following code and choose the correct option:class Test{ private static void display(){System.out.println("Display()");}private static void show() { display();System.out.println("show()");}public static void main(String arg[]){show();}}
180MCQ
181Compiles and prints show()
182Compiles and prints Display() show()
183Compiles but throws runtime exception
184Compilation error
1850
1861
1870
1880
189Access Specifiers Constructors Methods NewQB
190Which of the following sentences is true?A) Access to data member depends on the scope of the class and the scope of data membersB) Access to data member depends only on the scope of the data membersC) Access to data member depends on the scope of the method from where it is accessed
191MCQ
192Only A and C is TRUE
193All are TRUE
194All are FALSE
195Only A is TRUE
1960
1970
1980
1991
200Access Specifiers Constructors Methods NewQB
201Given: public class Yikes { public static void go(Long n) {System.out.print("Long ");} public static void go(Short n) {System.out.print("Short ");} public static void go(int n) {System.out.print("int ");} public static void main(String [] args) { short y = 6; long z = 7; go(y); go(z); } }What is the result?
202MCQ
203int Long
204Short Long
205Compilation fails.
206An exception is thrown at runtime.
2071
2080
2090
2100
211Access Specifiers Constructors Methods NewQB
212Which of the following will print -4.0
213MCQ
214System.out.println(Math.ceil(-4.7));
215System.out.println(Math.floor(-4.7));
216System.out.println(Math.round(-4.7));
217System.out.println(Math.min(-4.7));
2181
2190
2200
2210
222Access Specifiers Constructors Methods NewQB
223Suppose 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 constructorB) If class A has parameterized constructor, then class B can have default as well as parameterized constructorC) If class A has parameterized constructor then call to class A constructor should be made explicitly by constructor of class B
224MCQ
225Only B and C is TRUE
226Only A is TRUE
227All are FALSE
228Only A and C is TRUE
2291
2300
2310
2320
233Access Specifiers Constructors Methods NewQB
234class Order{Order(){System.out.println("Cat");}public static void main(String... Args){System.out.println("Ant");}static{System.out.println("Dog");}{System.out.println("Man");}}consider the code above & select the proper output from the options.
235MCQ
236Dog Ant
237Dog Man Cat Ant
238Man Dog Ant
239Dog Man Ant
2401
2410
2420
2430
244Access Specifiers Constructors Methods NewQB
245Consider the following code and choose the correct option:class A{ private void display(){ System.out.print("Hi");}public static void main(String ar[]){display();}}
246MCQ
247Compiles but doesn't display anything
248Compiles and throws run time exception
249Compilation fails
250Compiles and displays Hi
2510
2520
2531
2540
255Access Specifiers Constructors Methods NewQB
256Consider the following code and choose the correct option:public class MyClass { public static void main(String arguments[]) { amethod(arguments); } public void amethod(String[] arguments) { System.out.println(arguments[0]); System.out.println(arguments[1]); }}Command Line arguments - Hi, Hello
257MCQ
258prints Hi Hello
259Compiler Error
260Runs but no output
261Runtime Error
2620
2631
2640
2650
266Access Specifiers Constructors Methods NewQB
267package QB; class Sphere { protected int methodRadius(int r) { System.out.println("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 ?
268MCQ
269methodRadius(x);
270sp.methodRadius(x);
271Nothing to add
272Sphere.methodRadius();
2730
2741
2750
2760
277Access Specifiers Constructors Methods NewQB
278class One{int var1;One (int x){var1 = x;}}class Derived extends One{int var2;void display(){System.out.println("var 1="+var1+"var2="+var2);}}class Main{public static void main(String[] args){Derived obj = new Derived();obj.display();}}consider the code above & select the proper output from the options.
279MCQ
2800 , 0
281compiles successfully but runtime error
282compile error
283none of these
2840
2850
2861
2870
288Access Specifiers Constructors Methods NewQB
289Consider the following code and choose the correct option:class Test{ private void display(){System.out.println("Display()");}private static void show() { display();System.out.println("show()");}public static void main(String arg[]){show();}}
290MCQ
291Compiles and prints show()
292Compiles and prints Display() show()
293Compiles but throws runtime exception
294Compilation error
2950
2960
2970
2981
299Access Specifiers Constructors Methods NewQB
300Consider the following code and choose the best option:class Super{ int x; Super(){x=2;}}class Sub extends Super { void displayX(){System.out.print(x);}public static void main(String args[]){ new Sub().displayX();}}
301MCQ
302Compilation error
303Compiles and runs without any output
304Compiles and display 2
305Compiles and display 0
3060
3070
3081
3090
310Access Specifiers Constructors Methods NewQB
311class One{int var1;One (int x){var1 = x;}}class Derived extends One{int var2;Derived(){super(10);var2=10;}void display(){System.out.println("var1="+var1+" , var2="+var2);}}class Main{public static void main(String[] args){Derived obj = new Derived();obj.display();}}consider the code above & select the proper output from the options.
312MCQ
313var1=10 , var2=10
3140,0
315compile error
316runtime error
3171
3180
3190
3200
321Access Specifiers Constructors Methods NewQB
322public class MyAr { static int i1; public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); } public void amethod() { System.out.println(i1); }}What is the output of the program?
323MCQ
324Compilation Error
325Garbage Value
326It is not possible to access a static variable in side of non static method
3271
3280
3290
3300
331Access Specifiers Constructors Methods NewQB
332What 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: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); } }}
333MCQ
334Compilation Error
335default
336default zero
337default zero one two
3380
3390
3401
3410
342Access Specifiers Constructors Methods NewQB
343Which 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}}
344MCA
345i = this.planets;
346i = this.suns;
347this = new ThisUsage();
348this.i = 4;
349this.suns = planets;
3500.3
3510.33
3520
3530
3540.33
355Access Specifiers Constructors Methods NewQB
356Which modifier is used to control access to critical code in multi-threaded programs?
357MCQ
358default
359public
360transient
361synchronized
3620
3630
3640
3651
366Access Specifiers Constructors Methods NewQB
367Given:package QB;class Meal { Meal() { System.out.println("Meal()"); }}class Cheese { Cheese() { System.out.println("Cheese()"); }}class Lunch extends Meal { Lunch() { System.out.println("Lunch()"); }}class PortableLunch extends Lunch { PortableLunch() { System.out.println("PortableLunch()"); }}class Sandwich extends PortableLunch { private Cheese c = new Cheese(); public Sandwich() { System.out.println("Sandwich()"); }}public class MyClass7 { public static void main(String[] args) { new Sandwich();
368MCQ
369Meal() Lunch() PortableLunch() Cheese() Sandwich()
370Meal() Cheese() Lunch() PortableLunch() Sandwich()
371Meal() Lunch() PortableLunch() Sandwich() Cheese()
372Cheese() Sandwich() Meal() Lunch() PortableLunch()
3731
3740
3750
3760
377Access Specifiers Constructors Methods NewQB
378Consider 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(){System.out.print(a);}public static void main(String args[]){ new B().displayA();}}
379MCQ
380compiles and display 0
381compilation error
382Compiles and display 4
383Compiles and display 3
3841
3850
3860
3870
388Access Specifiers Constructors Methods NewQB
389Given 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(); p.amethod(i); System.out.println(i); System.out.println(j); } public void amethod(int x){ x=x*2; j=j*2; }}
390MCQ
391Error: amethod parameter does not match variable
39220 and 40
39310 and 40
39410, and 20
3950
3960
3971
3980
399Access Specifiers Constructors Methods NewQB
400What will happen if a main() method of a "testing" class tries to access a private instance variable of an object using dot notation?
401MCQ
402The compiler will automatically change the private variable to a public variable
403The compiler will find the error and will not make a .class file
404The program will compile and run successfully
405The program will compile successfully, but the .class file will not run correctly
4060
4071
4080
4090
410Access Specifiers Constructors Methods NewQB
41111. class Mud {12. // insert code here13. System.out.println("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?
412MCQ
4131
4142
4153
4160
4170
4180
4191
420Access Specifiers Constructors Methods NewQB
421class Order{Order(){System.out.println("Cat");}public static void main(String... Args){Order obj = new Order();System.out.println("Ant");}static{System.out.println("Dog");}{System.out.println("Man");}}consider the code above & select the proper output from the options.
422MCQ
423Man Dog Cat Ant
424Cat Ant Dog Man
425Dog Man Cat Ant
426compile error
4270
4280
4291
4300
431Access Specifiers Constructors Methods NewQB
432abstract 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 < ar.length;i++) System.out.println(ar[i]); }}
433MCQ
434A Sequence of 5 zero's will be printed like 0 0 0 0 0
435A Sequence of 5 one's will be printed like 1 1 1 1 1
436IndexOutOfBoundes Error
437Compilation Error occurs and to avoid them we need to declare Mine class as abstract
4380
4390
4400
4411
442Access Specifiers Constructors Methods NewQB
443public class Q { public static void main(String argv[]) { int anar[] = new int[] { 1, 2, 3 }; System.out.println(anar[1]); }}
444MCQ
445Compiler Error: anar is referenced before it is initialized
4462
4471
448Compiler Error: size of array must be defined
4490
4501
4510
4520
453Access Specifiers Constructors Methods NewQB
454A constructor may return value including class type
455MCQ
456true
457false
4580
4591
460Access Specifiers Constructors Methods NewQB
461Consider 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[]){ System.out.print(new S().roll);}}
462MCQ
463Compilation error
464Compiles and display 0
465Compiles and display 23
466Compiles but no output
4671
4680
4690
4700
471Access Specifiers Constructors Methods NewQB
472public class c123 { private c123() { System.out.println("Hellow"); } public static void main(String args[]) { c123 o1 = new c123(); c213 o2 = new c213(); }}class c213 { private c213() { System.out.println("Hello123"); }}What is the output?
473MCQ
474Hellow
475It is not possible to declare a constructor as private
476Compilation Error
477Runs without any output
4780
4790
4801
4810
482Access Specifiers Constructors Methods NewQB
483class MyClass1 { private int area(int side) { return(side * side); } public static void main(String args[ ]) { MyClass1 MC = new MyClass1( ); int area = MC.area(50); System.out.println(area); } } What would be the output?
484MCQ
485Compilation error
486Runtime Exception
4872500
48850
4890
4900
4911
4920
493Access Specifiers Constructors Methods NewQB
494public class MyAr { public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); } public void amethod() { static int i1; System.out.println(i1); }}What is the Output of the Program?
495MCQ
496Compile time error because i has not been initialized
497Compilation and output of null
498It is not possible to declare a static variable in side of non static method or instance method. Because Static variables are class level dependencies.
4990
5000
5010
5021
503Access Specifiers Constructors Methods NewQB
504public class MyAr { public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); } public void amethod() { final int i1; System.out.println(i1); }}What is the Output of the Program?
505MCQ
506Unresolved compilation problem: The local variable i1 may not have been initialized
507Compilation and output of null
508None of the given options
5090
5101
5110
5120
513Access Specifiers Constructors Methods NewQB
514public class c1 {private c1(){ System.out.println("Hello");}public static void main(String args[]){ c1 o1=new c1();}}What is the output?
515MCQ
516Hello
517It is not possible to declare a constructor private
518Compilation Error
519Can't create object because constructor is private
5201
5210
5220
5230
524Access Specifiers Constructors Methods NewQB
525Which modifier indicates that the variable might be modified asynchronously, so that all threads will get the correct value of the variable.
526MCQ
527synchronized
528volatile
529transient
530default
5310
5321
5330
5340
535Access Specifiers Constructors Methods NewQB
536class A { int i, j; A(int a, int b) { i = a; j = b; } void show() { System.out.println("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) { System.out.println(msg + k); }}class Override { public static void main(String args[]) { B subOb = new B(3, 5, 7); subOb.show("This is k: "); // this calls show() in B subOb.show(); // this calls show() in A }} What would be the ouput?
537MCQ
538This is j: 5 i and k: 3 7
539This is i: 3 j and k: 5 7
540This is i: 7 j and k: 3 5
541This is k: 7 i and j: 3 7
5420
5430
5440
5451
546Access Specifiers Constructors Methods NewQB
547Consider the following code and choose the correct option:class X { int x; X(int x){x=2;}}class Y extends X{ Y(){} void displayX(){System.out.print(x);}public static void main(String args[]){ new Y().displayX();}}
548MCQ
549Compiles and display 2
550Compiles and runs without any output
551Compiles and display 0
552Compilation error
5530
5540
5550
5561
557Access Specifiers Constructors Methods NewQB
558class Order{Order(){System.out.println("Cat");}public static void main(String... Args){Order obj = new Order();System.out.println("Ant");}static{System.out.println("Dog");}}consider the code above & select the proper output from the options.
559MCQ
560Cat Ant Dog
561Dog Cat Ant
562Ant Cat Dog
563none
5640
5651
5660
5670
568Access Specifiers Constructors Methods NewQB
569What will be the result when you attempt to compile this program? public class Rand{ public static void main(String argv[]){ int iRand; iRand = Math.random(); System.out.println(iRand); }}
570MCQ
571Compile time error referring to a cast problem
572A random number between 1 and 10
573A random number between 0 and 1
574A compile time error as random being an undefined method
5751
5760
5770
5780
579Annotations_NewQB
580Choose the meta annotations. (Choose THREE)
581MCA
582Override
583Retention
584Depricated
585Documented
586Target
5870
5880.33
5890
5900.3
5910.33
592Annotations_NewQB
593If no retention policy is specified for an annotation, then the default policy of __________ is used.
594MCQ
595method
596class
597source
598runtime
5990
6001
6010
6020
603Annotations_NewQB
604Select the variable which are in java.lang.annotation.RetentionPolicy class. (Choose THREE)
605MCA
606SOURCE
607METHOD
608RUNTIME
609CONSTRUCTOR
610CLASS
6110.3
6120
6130.3
6140
6150.33
616Annotations_NewQB
617Select the Uses of annotations. (Choose THREE)
618MCA
619Information For the Compiler
620Information for the JVM
621Compile time and deploytime processing
622Runtime processing
623Information for the OS
6240.3
6250
6260.3
6270.3
6280
629Annotations_NewQB
630All annotation types should maually extend the Annotation interface. State TRUE/FALSE
631MCQ
632true
633false
6340
6351
636Annotations_NewQB
637Custom annotations can be created using
638MCQ
639@interface
640@inherit
641@include
642all the listed options
6431
6440
6450
6460
647Collections_util_NewQB
648Given: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. java.util.List<a> list = new java.util.ArrayList</a>();21. list.add(new B());22. list.add(new C());23. for (A a:list) {24. a.x();25. a.y();;26. }What is the result?
649MCQ
650Compilation fails because of an error in line 25
651The code runs with no output.
652An exception is thrown at runtime
653Compilation fails because of an error in line 21
654Compilation fails because of an error in line 23.
6551
6560
6570
6580
6590
660Collections_util_NewQB
661Given: public static Collection get() { Collection sorted = new LinkedList(); sorted.add("B"); sorted.add("C"); sorted.add("A"); return sorted; } public static void main(String[] args) { for (Object obj: get()) { System.out.print(obj + ", "); } }What is the result?
662MCQ
663A, B, C,
664B, C, A,
665Compilation fails.
666An exception is thrown at runtime.
6670
6681
6690
6700
671Collections_util_NewQB
672Which statement is true about the following program?import java.util.ArrayList;import java.util.Collections;import java.util.List;public class WhatISThis {public static void main(String[] na){List<StringBuilder> list=new ArrayList<StringBuilder>();list.add(new StringBuilder("B"));list.add(new StringBuilder("A"));list.add(new StringBuilder("C"));Collections.sort(list,Collections.reverseOrder());System.out.println(list.subList(1,2));}}
673MCQ
674The program will compile and print the following output: [B]
675The program will compile and print the following output: [B,A]
676The program will compile and throw a runtime exception
677The program will not compile
6780
6790
6801
6810
682Collections_util_NewQB
683Consider the following code and choose the correct option:public static void before() {Set set = new TreeSet();set.add("2");set.add(3);set.add("1");Iterator it = set.iterator();while (it.hasNext())System.out.print(it.next() + " ");}
684MCQ
685The before() method will print 1 2
686The before() method will print 1 2 3
687The before() method will throw an exception at runtime
688The before() method will not compile
6890
6900
6911
6920
693Collections_util_NewQB
694import java.util.StringTokenizer;class ST{public static void main(String[] args){String input = "Today is$Holiday";StringTokenizer st = new StringTokenizer(input,"$");while(st.hasMoreTokens()){System.out.println(st.nextElement());}}
695MCQ
696Today is Holiday
697Today is Holiday
698Both
699none of the listed options
7000
7011
7020
7030
704Collections_util_NewQB
705Given: public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.add("1"); list.add("2"); list.add("3"); for (Object obj: reverse(list)) System.out.print(obj + ", "); }What is the result?
706MCQ
7073, 2, 1,
7081, 2, 3,
709Compilation fails.
710The code runs with no output.
7110
7120
7131
7140
715Collections_util_NewQB
716Which collection class allows you to grow or shrink its size and provides indexed access toits elements, but its methods are not synchronized?
717MCQ
718java.util.HashSet
719java.util.LinkedHashSet
720java.util.List
721java.util.ArrayList
722java.util.Vector
7230
7240
7250
7261
7270
728Collections_util_NewQB
729int indexOf(Object o) - What does this method return if the element is not found in the List?
730MCQ
731null
732-1
733none of the listed options
7340
7351
7360
7370
738Collections_util_NewQB
739What is the result of attempting to compile and run the following code? import java.util.Vector; import java.util.LinkedList; public class Test1{ public static void main(String[] args) { Integer int1 = new Integer(10); Vector vec1 = new Vector(); LinkedList list = new LinkedList(); vec1.add(int1); list.add(int1); if(vec1.equals(list)) System.out.println("equal"); else System.out.println("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".
740MCQ
7411
7422
7433
7444
7450
7460
7471
7480
749Collections_util_NewQB
750Consider the following code and choose the correct option:class Test{ public static void main(String args[]){ Integer arr[]={3,4,3,2}; Set<Integer> s=new TreeSet<Integer>(Arrays.asList(arr)); s.add(1); for(Integer ele :s){ System.out.println(ele); } }}
751MCQ
752Compilation error
753prints 3,4,2,1,
754prints 1,2,3,4
755Compiles but exception at runtime
7560
7570
7581
7590
760Collections_util_NewQB
761Inorder to remove one element from the given Treeset, place the appropriate line of code public class Main { public static void main(String[] args) { TreeSet<Integer> tSet = new TreeSet<Integer>(); System.out.println("Size of TreeSet : " + tSet.size()); tSet.add(new Integer("1")); tSet.add(new Integer("2")); tSet.add(new Integer("3")); System.out.println(tSet.size()); // remove the one element from the Treeset System.out.println("Size of TreeSet after removal : " + tSet.size()); }}
762MCQ
763tSet.clear(new Integer("1"));
764tSetdelete(new Integer("1"));
765tSet.remove(new Integer("1"));
766tSet.drop(new Integer("1"));
7670
7680
7691
7700
771Collections_util_NewQB
772Consider 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"}; Arrays.sort(colors); int s1=Arrays.binarySearch(colors, "ivory"); int s2=Arrays.binarySearch(colors, "silver"); System.out.println(s1+" "+s2); }}
773MCQ
7742 -4
7753 -5
7762 -6
7773 -4
7780
7790
7801
7810
782Collections_util_NewQB
783Consider the following code and choose the correct output:class Test{ public static void main(String args[]){ TreeMap<Integer, String> hm=new TreeMap<Integer, String>(); hm.put(2,"Two"); hm.put(4,"Four"); hm.put(1,"One"); hm.put(6,"Six"); hm.put(7,"Seven"); SortedMap<Integer, String> sm=hm.subMap(2,7); SortedMap<Integer,String> sm2=sm.tailMap(4); System.out.print(sm2); }}
784MCQ
785{2=Two, 4=Four, 6=Six, 7=Seven}
786{4=Four, 6=Six, 7=Seven}
787{4=Four, 6=Six}
788{2=Two, 4=Four, 6=Six}
7890
7900
7911
7920
793Collections_util_NewQB
794next() method of Scanner class will return _________
795MCQ
796Integer
797Long
798int
799String
8000
8010
8020
8031
804Collections_util_NewQB
805Given:import java.util.Arrays;import java.util.HashSet;import java.util.Set;public class MainClass { public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); elements = new String[] { "A", "B", "C", "D" }; Set set2 = new HashSet(Arrays.asList(elements)); System.out.println(set.equals(set2)); }} What is the result of given code?
806MCQ
807true
808false
809Compile time error
810Runtime Exception
8110
8121
8130
8140
815Collections_util_NewQB
816A)Property files help to decrease couplingB) 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
817MCQ
818A and B is TRUE
819A and D is TRUE
820A and C is TRUE
821B and D is TRUE
8220
8230
8241
8250
826Collections_util_NewQB
827Which interface does java.util.Hashtable implement?
828MCQ
829Java.util.Map
830Java.util.List
831Java.util.Table
832Java.util.Collection
8331
8340
8350
8360
837Collections_util_NewQB
838Object get(Object key) - What does this method return if the key is not found in the Map?
839MCQ
840-1
841null
842none of the listed options
8430
8440
8451
8460
847Collections_util_NewQB
848Consider the following code and choose the correct option:class Test{ public static void main(String args[]){ TreeSet<Integer> ts=new TreeSet<Integer>(); ts.add(1); ts.add(8); ts.add(6); ts.add(4); SortedSet<Integer> ss=ts.subSet(2, 10); ss.add(9); System.out.println(ts); System.out.println(ss); }}
849MCQ
850[1,4,6,8] [4,6,8,9]
851[1,8,6,4] [8,6,4,9]
852[1,4,6,8,9] [4,6,8,9]
853[1,4,6,8,9] [4,6,8]
8540
8550
8561
8570
858Collections_util_NewQB
859A) Iterator does not allow to insert elements during traversalB) Iterator allows bidirectional navigation.C) ListIterator allows insertion of elements during traversalD) ListIterator does not support bidirectional navigation
860MCQ
861A and B is TRUE
862A and D is TRUE
863A and C is TRUE
864B and D is TRUE
8650
8660
8671
8680
869Collections_util_NewQB
870static void sort(List list) method is part of ________
871MCQ
872Collection interface
873Collections class
874Vector class
875ArrayList class
8760
8771
8780
8790
880Collections_util_NewQB
881static int binarySearch(List list, Object key) is a method of __________
882MCQ
883Vector class
884ArrayList class
885Collection interface
886Collections class
8870
8880
8890
8901
891Collections_util_NewQB
892Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?
893MCQ
894java.util.SortedMap
895java.util.TreeMap
896java.util.TreeSet
897java.util.Hashtable
8980
8990
9000
9011
902Collections_util_NewQB
903Consider the following code and select the correct output:import java.util.ArrayList;import java.util.LinkedList;import java.util.List;public class Lists {public static void main(String[] args) {List<String> list=new ArrayList<String>();list.add("1");list.add("2");list.add(1, "3");List<String> list2=new LinkedList<String>(list);list.addAll(list2);list2 =list.subList(2,5);list2.clear();System.out.println(list);}}
904MCQ
905[1,3,2]
906[1,3,3,2]
907[1,3,2,1,3,2]
908[3,1,2]
909[3,1,1,2]
9101
9110
9120
9130
9140
915Collections_util_NewQB
916Given: import java.util.*; public class LetterASort{ public static void main(String[] args) { ArrayList<String> strings = new ArrayList<String>(); strings.add("aAaA"); strings.add("AaA"); strings.add("aAa"); strings.add("AAaa"); Collections.sort(strings); for (String s : strings) { System.out.print(s + " "); } } }What is the result?
917MCQ
918Compilation fails.
919aAaA aAa AAaa AaA
920AAaa AaA aAa aAaA
921AaA AAaa aAaA aAa
9220
9230
9241
9250
926Collections_util_NewQB
927A) 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 InsertionD)TreeSet maintains order of Inserstion
928MCQ
929A and B is TRUE
930A and D is TRUE
931A and C is TRUE
932B and C is TRUE
9330
9340
9350
9361
937Collections_util_NewQB
938TreeSet<String> s = new TreeSet<String>(); TreeSet<String> subs = new TreeSet<String>(); s.add("a"); s.add("b"); s.add("c"); s.add("d"); s.add("e"); subs = (TreeSet)s.subSet("b", true, "d", true); s.add("g"); s.pollFirst(); s.pollFirst(); s.add("c2"); System.out.println(s.size() +" "+ subs.size());
939MCA
940The size of s is 4
941The size of s is 5
942The size of subs is 3
943The size of s is 7
944The size of subs is 1
9450
9460.5
9470.5
9480
9490
950Collections_util_NewQB
951Consider 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"); System.out.print(sd.format(date));}}
952MCQ
953Wed Jun 01 1983
954244 JUN 01 1983
955PST JUN 01 1983
956GMT JUN 01 1983
9571
9580
9590
9600
961Collections_util_NewQB
962Given: 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) System.out.print(a[0]); } } What is the result?
963MCQ
964123
96512
96614
9671
9680
9690
9701
9710
972Collections_util_NewQB
973You 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) TreeSet2) HashMap3) LinkedList4) an array
974MCQ
9751
9762
9773
9784
9790
9800
9810
9821
983Collections_util_NewQB
984What will be the output of following code?class Test{ public static void main(String args[]){ TreeSet<Integer> ts=new TreeSet<Integer>(); ts.add(2); ts.add(3); ts.add(7); ts.add(5);SortedSet<Integer> ss=ts.subSet(1,7); ss.add(4); ss.add(6);System.out.print(ss);}}
985MCQ
986[2,3,7,5]
987[2,3,7,5,4,6]
988[2,3,4,5,6,7]
989[2,3,4,5,6]
9900
9910
9920
9931
994Collections_util_NewQB
995Consider 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[]){ Set<Data> s=new HashSet<Data>(); s.add(new Data(4)); s.add(new Data(2)); s.add(new Data(4)); s.add(new Data(1)); s.add(new Data(2)); System.out.print(s.size());}}
996MCQ
9973
9985
999compilation error
1000Compiles but error at run time
10010
10021
10030
10040
1005Control structures wrapper classes auto boxing NewQB
1006Consider 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;x<3;x++) for(int y=0;y<2;y++){ if(x==1) break; if(x==2 && y==1) break z; num=num+x+y; }System.out.println(num);}}
1007MCQ
10080001
1009000120
101000012021
1011Compilation error
10120
10131
10140
10150
1016Control structures wrapper classes auto boxing NewQB
1017Given: public class Test { public enum Dogs {collie, harrier}; public static void main(String [] args) { Dogs myDog = Dogs.collie; switch (myDog) { case collie: System.out.print("collie "); case harrier: System.out.print("harrier "); } } }What is the result?
1018MCQ
1019collie
1020harrier
1021Compilation fails.
1022collie harrier
10230
10240
10250
10261
1027Control structures wrapper classes auto boxing NewQB
1028Consider the following code and choose the correct output:class Test{ public static void main(String args[]){ boolean flag=true; if(flag=false){ System.out.print("TRUE");}else{ System.out.print("FALSE");}}}
1029MCQ
1030true
1031false
1032compilation error
1033Compiles
10340
10351
10360
10370
1038Control structures wrapper classes auto boxing NewQB
1039Cosider the following code and choose the correct option: class Test{ public static void main(String args[]){ System.out.println(Integer.parseInt("2147483648", 10)); }}
1040MCQ
1041Compilation error
10422.147483648E9
1043NumberFormatException at run time
1044Compiles but no output
10450
10460
10471
10480
1049Control structures wrapper classes auto boxing NewQB
1050Given: public class Test { public enum Dogs {collie, harrier, shepherd}; public static void main(String [] args) { Dogs myDog = Dogs.shepherd; switch (myDog) { case collie: System.out.print("collie "); case default: System.out.print("retriever "); case harrier: System.out.print("harrier "); } } }What is the result?
1051MCQ
1052harrier
1053shepherd
1054retriever
1055Compilation fails.
10560
10570
10580
10591
1060Control structures wrapper classes auto boxing NewQB
1061Given:static void myFunc() { int i, s = 0; for (int j = 0; j < 7; j++) { i = 0; do { i++; s++; } while (i < j); } System.out.println(s); } } What would be the result
1062MCQ
106320
106421
106522
106623
106724
10680
10690
10701
10710
10720
1073Control structures wrapper classes auto boxing NewQB
1074What is the range of the random number r generated by the code below?int r = (int)(Math.floor(Math.random() * 8)) + 2;
1075MCQ
10762 <= r <= 9
10773 <= r <= 10
10782<= r <= 10
10793 <= r <= 9
10801
10810
10820
10830
1084Control structures wrapper classes auto boxing NewQB
1085class Test{ public static void main(String[] args) { int x=-1,y=-1; if(++x=++y) System.out.println("R.T. Ponting"); else System.out.println("C.H. Gayle"); }}consider the code above & select the proper output from the options.
1086MCQ
1087R.T.Ponting
1088C.H.Gayle
1089Compile error
1090none of the listed options
10910
10920
10931
10940
1095Control structures wrapper classes auto boxing NewQB
1096Given: 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; } System.out.println(o); } }What is the result?
1097MCQ
10982
109924
1100234
1101246
11020
11031
11040
11050
1106Control structures wrapper classes auto boxing NewQB
1107Consider the following code and choose the correct output:class Test{ public static void main(String args[]){ int a=5; if(a=3){ System.out.print("Three");}else{ System.out.print("Five");}}}
1108MCQ
1109Compilation error
1110Three
1111Five
1112Compiles but no output
11131
11140
11150
11160
1117Control structures wrapper classes auto boxing NewQB
1118Given: public class Batman { int squares = 81; public static void main(String[] args) { new Batman().go(); } void go() { incr(++squares); System.out.println(squares); } void incr(int squares) { squares += 10; } }What is the result?
1119MCQ
112081
112182
112291
112392
11240
11251
11260
11270
1128Control structures wrapper classes auto boxing NewQB
1129public void foo( boolean a, boolean b){ if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } }What would be the result?
1130MCQ
1131If a is true and b is false then the output is "notB"
1132If a is true and b is true then the output is "A && B"
1133If a is false and b is false then the output is "ELSE"
1134If a is false and b is true then the output is "ELSE"
11350
11360
11370
11381
1139Control structures wrapper classes auto boxing NewQB
1140What 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;}
1141MCQ
114214
114328
1144Compilation Error
114510
1146Runtime Error
11470
11480
11491
11500
11510
1152Control structures wrapper classes auto boxing NewQB
1153public 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?
1154MCQ
1155There is a syntax error on line 1
1156There are syntax errors on lines 1 and 6
1157There are syntax errors on lines 1, 6, and 8
1158There is a syntax error on line 6
11590
11600
11610
11621
1163Control structures wrapper classes auto boxing NewQB
1164Which 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?>}
1165MCQ
1166s += i * i;
1167s++;
1168s = s + s * i;
1169s *= i;
1170Compilation error
11710
11720
11730
11741
11750
1176Control structures wrapper classes auto boxing NewQB
1177Which of the following statements are true regarding wrapper classes? (Choose TWO)
1178MCA
1179String is a wrapper class
1180Double has a compareTo() method
1181Character has a intValue() method
1182Byte extends Number
1183String is the wrapper class of char
11840
11850.5
11860
11870.5
11880
1189Control structures wrapper classes auto boxing NewQB
1190Given: class Atom { Atom() { System.out.print("atom "); } } class Rock extends Atom { Rock(String type) { System.out.print(type); }} public class Mountain extends Rock { Mountain() { super("granite "); new Rock("granite "); } public static void main(String[] a) { new Mountain(); } }What is the result?
1191MCQ
1192Compilation fails.
1193granite granite
1194atom granite granite
1195atom granite atom granite
11960
11970
11980
11991
1200Control structures wrapper classes auto boxing NewQB
1201What are the thing to be placed to complete the code?class Wrap { public static void main(String args[]) { _______________ iOb = ___________ Integer(100); int i = iOb.intValue(); System.out.println(i + " " + iOb); // displays 100 100 }}
1202MCQ
1203int, int
1204Integer, new
1205Integer, int
1206int, Integer
12070
12081
12090
12100
1211Control structures wrapper classes auto boxing NewQB
1212public class SwitchTest { public static void main(String[] args) { System.out.println("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?
1213MCQ
1214value = 8
1215value = 2
1216value = 4
1217value = 6
12181
12190
12200
12210
1222Control structures wrapper classes auto boxing NewQB
1223Given: 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) { System.out.print(y[y.length - 1] + " "); } }What is the result?
1224MCQ
1225hi hi
1226hi world
1227world world
1228Compilation fails.
12290
12300
12310
12321
1233Control structures wrapper classes auto boxing NewQB
1234Consider 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; System.out.println(ans); }}
1235MCQ
123640
123746
1238compilation error
1239Compiles but error at run time
12401
12410
12420
12430
1244Control structures wrapper classes auto boxing NewQB
124511. double input = 314159.26;12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);13. String b;14. //insert code hereWhich code, inserted at line 14, sets the value of b to 314.159,26?
1246MCQ
1247b = nf.parse( input );
1248b = nf.format( input );
1249b = nf.equals( input );
1250b = nf.parseObject( input );
12510
12521
12530
12540
1255Control structures wrapper classes auto boxing NewQB
1256Consider the following code and choose the correct option:class Test{public static void main(String ar[]){ TreeMap<Integer,String> tree = new TreeMap<Integer,String>(); tree.put(1, "one"); tree.put(2, "two"); tree.put(3, "three"); tree.put(4,"Four"); System.out.println(tree.higherKey(2)); System.out.println(tree.ceilingKey(2)); System.out.println(tree.floorKey(1)); System.out.println(tree.lowerKey(1));}}
1257MCQ
12583 2 1 null
12593 2 1 1
12602 2 1 1
12614 2 1 1
12621
12630
12640
12650
1266Control structures wrapper classes auto boxing NewQB
1267Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long data=23; System.out.println(data); }}
1268MCQ
126923
1270Compilation error
1271Compiles but error at run time
1272None of the listed options
12730
12741
12750
12760
1277Control structures wrapper classes auto boxing NewQB
1278class AutoBox { public static void main(String args[]) { int i = 10; Integer iOb = 100; i = iOb; System.out.println(i + " " + iOb); } } whether this code work properly, if so what would be the result?
1279MCQ
1280No, Compilation error
1281No, Runtime error
1282Yes, 10, 100
1283Yes, 100, 100
12840
12850
12860
12871
1288Control structures wrapper classes auto boxing NewQB
1289Consider the following code and choose the correct option: class Test{ public static void main(String args[]){ Long l=0l; System.out.println(l.equals(0));}}
1290MCQ
1291Compilation error
1292true
1293false
12941
12950
12960
12971
12980
1299Control structures wrapper classes auto boxing NewQB
1300int 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; }System.out.println(I);What will be thr result?
1301MCQ
13023
13032
13044
13051
13060
13070
13080
13091
1310Control structures wrapper classes auto boxing NewQB
1311what 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(i<10)System.out.println("a");elseSystem.out.println("b");}}
1312MCQ
1313The code will fail to compile because the syntax of the if statement is incorrect
1314The code will fail to compile because the compiler will not be able to determine which if statement the else clause belongs to
1315The code will compile correctly and display the letter a,when run
1316The code will compile correctly and display the letter b,when run
1317The code will compile correctly,but will not display any output
13180
13190
13200
13211
13220
1323Control structures wrapper classes auto boxing NewQB
1324What is the output of the following code :class try1{ public static void main(String[] args) { System.out.println("good"); while(false){ System.out.println("morning"); } }}
1325MCQ
1326good
1327good morning morning ….
1328compiler error
1329runtime error
13300
13310
13321
13330
1334Control structures wrapper classes auto boxing NewQB
1335Consider 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: { System.out.println("bat man"); } case 2: case 5: { System.out.println("spider man"); }break; } }}
1336MCQ
1337bat man
1338Compilation error
1339bat man spider man
1340spider man
13410
13420
13431
13440
1345Control structures wrapper classes auto boxing NewQB
1346Given: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;}System.out.println(n);What is the value of ’n’ after executing the following code?
1347MCQ
134823
134932
135025
1351Compilation Error
1352Runtine Error
13530
13540
13551
13560
13570
1358Control structures wrapper classes auto boxing NewQB
1359What will be the output of following code? TreeSet map = new TreeSet();map.add("one");map.add("two");map.add("three");map.add("four");map.add("one");Iterator it = map.iterator();while (it.hasNext() ) { System.out.print( it.next() + " " );}
1360MCQ
1361one two three four
1362four three two one
1363four one three two
1364one two three four one
13650
13660
13671
13680
1369Control structures wrapper classes auto boxing NewQB
1370public class Test { public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 )System.out.print("3 "); } }What is the result?
1371MCQ
13722
13733
13742 3
13751 2 3
13760
13770
13781
13790
1380Control structures wrapper classes auto boxing NewQB
1381Which of these statements are true?
1382MCA
1383HashTable is a sub class of Dictionary
1384ArrayList is a sub class of Vector
1385LinkedList is a subclass of ArrayList
1386Stack is a subclass of Vector
13870.5
13880
13890
13900.5
1391Control structures wrapper classes auto boxing NewQB
1392Given: import java.util.*; public class Explorer3 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i = 606; i < 613; i++) if(i%2 == 0) s.add(i); subs = (TreeSet)s.subSet(608, true, 611, true); subs.add(629); System.out.println(s + " " + subs); } }What is the result?
1393MCQ
1394Compilation fails.
1395[608, 610, 612, 629] [608, 610]
1396An exception is thrown at runtime.
1397[608, 610, 612, 629] [608, 610, 629]
13980
13990
14001
14010
1402Control structures wrapper classes auto boxing NewQB
1403What is the output :class try1{ public static void main(String[] args) { int x=1; if(x--) System.out.println("good"); else System.out.println("bad"); } }
1404MCQ
1405good
1406bad
1407compile error
1408run time error
14090
14100
14111
14120
1413Control structures wrapper classes auto boxing NewQB
1414Consider the following code and choose the correct output:class Test{ public static void main(String args[]){ int num='b'; switch(num){ default :{ System.out.print("default");} case 100 : case 'b' : case 'c' : { System.out.println("brownie"); break;} case 200: case 'e': { System.out.println("pastry"); }break; } }}
1415MCQ
1416brownie
1417default brownie
1418compilation error
1419default
14201
14210
14220
14230
1424Control structures wrapper classes auto boxing NewQB
1425Given: int a = 5;int b = 5;int c = 5;if (a > 3)if (b > 4)if (c > 5)c += 1;elsec += 2;elsec += 3;c += 4;What is the value of variable c after executing the following code?
1426MCQ
14273
14285
14297
14309
143111
14320
14330
14340
14350
14361
1437Control structures wrapper classes auto boxing NewQB
1438Given: Float pi = new Float(3.14f); if (pi > 3) { System.out.print("pi is bigger than 3. "); } else { System.out.print("pi is not bigger than 3. "); } finally { System.out.println("Have a nice day."); }What is the result?
1439MCQ
1440Compilation fails.
1441pi is bigger than 3.
1442An exception occurs at runtime.
1443pi is bigger than 3. Have a nice day.
14441
14450
14460
14470
1448Control structures wrapper classes auto boxing NewQB
1449Given: 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; } } System.out.println(o); }What is the result when the go() method is invoked?
1450MCQ
145100
14520001
1453000120
145400012021
14550
14560
14571
14580
1459Control structures wrapper classes auto boxing NewQB
1460Examine the following code: int count = 1; while ( ___________ ) { System.out.print( count + " " ); count = count + 1; } System.out.println( );What condition should be used so that the code prints: 1 2 3 4 5 6 7 8
1461MCQ
1462count < 9
1463count+1 <= 8
1464count < 8
1465count != 8
14661
14670
14680
14690
1470Control structures wrapper classes auto boxing NewQB
1471What 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: System.out.print("0 "); /* Line 11 */ case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ } } }}
1472MCQ
14730 1 2
14740 1 2 1 2 2
1475Compilation fails at line 11
1476Compilation fails at line 12.
14770
14780
14791
14800
1481Control structures wrapper classes auto boxing NewQB
1482Given: int x = 0; int y = 10; do { y--; ++x; } while (x < 5); System.out.print(x + "," + y);What is the result?
1483MCQ
14845,6
14855,5
14866,5
14876,6
14880
14891
14900
14910
1492Control structures wrapper classes auto boxing NewQB
1493What is the output :class Test{ public static void main(String[] args) { int a=5,b=10,c=1; if(a>c){ System.out.println("success"); } else{ break; } } }
1494MCQ
1495success
1496runtime error
1497compiler error
1498none of the listed options
14990
15000
15011
15020
1503Control structures wrapper classes auto boxing NewQB
1504Consider 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); System.out.print(x + "," + y);}}
1505MCQ
15065,6
15075,5
15086,5
15096,6
15100
15111
15120
15130
1514Control structures wrapper classes auto boxing NewQB
1515Consider the following code and choose the correct option:class Test{ public static void main(String args[]){ int l=7; Long L = (Long)l; System.out.println(L); }}
1516MCQ
15177
1518Compilation error
1519Compiles but error at run time
1520None of the listed options
15210
15221
15230
15240
1525Control structures wrapper classes auto boxing NewQB
1526Given:double height = 5.5; if(height-- >= 5.0) System.out.print("tall "); if(--height >= 4.0) System.out.print("average "); if(height-- >= 3.0) System.out.print("short "); else System.out.print("very short "); }What would be the Result?
1527MCQ
1528tall
1529tall short
1530short
1531very short
1532average
15330
15341
15350
15360
15370
1538Control structures wrapper classes auto boxing NewQB
1539Consider the following code and choose the correct option:class Test{ public static void main(String args[]){ String hexa = "0XFF"; int number = Integer.decode(hexa); System.out.println(number); }}
1540MCQ
1541Compilation error
15421515
1543255
1544Compiles but error at run time
15450
15460
15471
15480
1549Control structures wrapper classes auto boxing NewQB
1550Consider 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; } System.out.println("j = " + j);
1551MCQ
1552j = -1
1553j = 0
1554j = 1
1555Compilation fails
15560
15570
15580
15591
1560Control structures wrapper classes auto boxing NewQB
1561Which of the following statements about arrays is syntactically wrong?
1562MCQ
1563Person[] p = new Person[5];
1564Person p[5];
1565Person[] p [];
1566Person p[][] = new Person[2][];
15670
15681
15690
15700
1571Control structures wrapper classes auto boxing NewQB
1572What will be the output of following code? import java.util.*; class I { public static void main (String[] args) { Object i = new ArrayList().iterator(); System.out.print((i instanceof List)+","); System.out.print((i instanceof Iterator)+","); System.out.print(i instanceof ListIterator); } }
1573MCQ
1574Prints: false, false, false
1575Prints: false, false, true
1576Prints: false, true, false
1577Prints: false, true, true
15780
15790
15801
15810
1582Control structures wrapper classes auto boxing NewQB
1583Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } }and the invocation: test("four"); test("tee"); test("to");What is the result?
1584MCQ
1585r, t, t,
1586r, e, o,
1587Compilation fails.
1588An exception is thrown at runtime.
15890
15900
15911
15920
1593Control structures wrapper classes auto boxing NewQB
1594What will be the output of the program? int x = 3; int y = 1; if (x = y) /* Line 3 */{ System.out.println("x =" + x); }
1595MCQ
1596x = 1
1597x = 3
1598Compilation fails.
1599The code runs with no output.
16000
16010
16021
16030
1604Control structures wrapper classes auto boxing NewQB
1605import java.util.SortedSet;import java.util.TreeSet;public class Main { public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("4"); tSet.add("5"); SortedSet sortedSet =_____________("3"); System.out.println("Head Set Contains : " + sortedSet); }} What is the missing method in the code to get the head set of the tree set?
1606MCQ
1607tSet.headSet
1608tset.headset
1609headSet
1610HeadSet
16111
16120
16130
16140
1615Control structures wrapper classes auto boxing NewQB
1616Consider the following code and choose the correct output:class Test{ public static void main(String args[]){ int num=3; switch(num){ default :{ System.out.print("default");} case 1: case 3: case 4: { System.out.println("apple"); break;} case 2: case 5: { System.out.println("black berry"); }break; } }}
1617MCQ
1618apple
1619default apple
1620compilation error
1621default
16221
16230
16240
16250
1626Control structures wrapper classes auto boxing NewQB
1627Consider the following code and choose the correct option:class Test{ public static void main(String args[]){ Long L = null; long l = L; System.out.println(L); System.out.println(l); }}
1628MCQ
1629null 0
1630Compilation error
1631Compiles but error at run time
16320 null
16330
16340
16351
16360
1637Control structures wrapper classes auto boxing NewQB
1638What does the following code fragment write to the monitor? int sum = 21; if ( sum != 20 ) System.out.print("You win ");else System.out.print("You lose ");System.out.println("the prize.");What does the code fragment prints?
1639MCQ
1640You win the prize
1641You lose the prize.
1642You win
1643You lose
16441
16450
16460
16470
1648Control structures wrapper classes auto boxing NewQB
1649Which statements are true about maps? (Choose TWO)
1650MCA
1651The return type of the values() method is set
1652Changes made in the Set view returned by keySet() will be reflected in the original map
1653The Map interface extends the Collection interface
1654All keys in a map are unique
1655All Map implementations keep the keys sorted
16560
16570.5
16580
16590.5
16600
1661Control structures wrapper classes auto boxing NewQB
1662Which 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?
1663MCQ
1664TreeMap
1665HashSet
1666Vector
1667LinkedList
1668ArrayList
16690
16700
16710
16721
16730
1674Control structures wrapper classes auto boxing NewQB
1675Choose TWO correct options:
1676MCA
1677OutputStream is the abstract superclass of all classes that represent an outputstream of bytes.
1678Subclasses of the class Reader are used to read character streams.
1679To write characters to an outputstream, you have to make use of the class CharacterOutputStream.
1680To write an object to a file, you use the class ObjectFileWriter
16810.5
16820.5
16830
16840
1685Control structures wrapper classes auto boxing NewQB
1686What is the output :class One{ public static void main(String[] args) { int a=100; if(a>10) System.out.println("M.S.Dhoni"); else if(a>20) System.out.println("Sachin"); else if(a>30) System.out.println("Virat Kohli");} }
1687MCQ
1688M.S.Dhoni
1689M.S.Dhoni Sachin Virat Kohli
1690Virat Kohli
1691all of these
16921
16930
16940
16950
1696Control structures wrapper classes auto boxing NewQB
1697Which of the following statements is TRUE regarding a Java loop?
1698MCQ
1699A continue statement doesn’t transfer control to the test statement of the for loop
1700An overflow error can only occur in a loop
1701A loop may have multiple exit points
1702If a variable of type int overflows during the execution of a loop, it will cause an exception
17030
17040
17051
17060
1707Control structures wrapper classes auto boxing NewQB
1708switch(x) { default: System.out.println("Hello"); }Which of the following are acceptable types for x? 1.byte 2.long 3.char 4.float 5.Short 6.Long
1709MCQ
17101 ,3 and 5
17112 and 4
17123 and 5
17134 and 6
17141
17150
17160
17170
1718Exception_handling_NewQB
1719Which are true with respect to finally block? (Choose THREE)
1720MCA
1721Used to release the resources which are obtained in try block.
1722Writing finally block is optional.
1723When an exception occurs then a part of try block will execute one appropriate catch block and finally block will be executed.
1724finally block will never execute when no exceptions are there.
1725When no exception occurs then complete try block and finally block
17260.3
17270.25
17280.3
17290
17300.25
1731Exception_handling_NewQB
1732What 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(); b.run(); } public void start(){ for (int i = 0; i <10; i++){ System.out.println("Value of i = " + i); } }}
1733MCQ
1734A compile time error indicating that no run method is defined for the Thread class
1735A run time error indicating that no run method is defined for the Thread class
1736Clean compile and at run time the values 0 to 9 are printed out
1737Clean compile but no output at runtime
17380
17390
17400
17411
1742Exception_handling_NewQB
1743Given: public void testIfA() { if (testIfB("True")) { System.out.println("True"); } else { System.out.println("Not true"); } } public Boolean testIfB(String str) { return Boolean.valueOf(str); }What is the result when method testIfA is invoked?
1744MCQ
1745true
1746Not true
1747An exception is thrown at runtime.
1748none
17491
17500
17510
17520
1753Exception_handling_NewQB
1754Which of the following statements are true? (Choose TWO)
1755MCA
1756Deadlock will not occur if wait()/notify() is used
1757The wait() method is overloaded to accept a duration
1758A thread will resume execution as soon as its sleep duration expires.
1759The notify() method is overloaded to accept a duration
1760Both wait() and notify() must be called from a synchro
17610
17620.33
17630.3
17640
17650.33
1766Exception_handling_NewQB
1767public class MyProgram { public static void throwit() { throw new RuntimeException(); } public static void main(String args[]) { try { System.out.println("Hello world "); throwit(); System.out.println("Done with try block "); } finally { System.out.println("Finally executing "); } }}which answer most closely indicates the behavior of the program?
1768MCQ
1769The program will not compile.
1770The 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.
1771The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing.
1772The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred.
17730
17740
17750
17761
1777Exception_handling_NewQB
1778If 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
1779MCQ
1780false
1781true
17820
17831
1784Exception_handling_NewQB
1785A) 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.
1786MCQ
1787Only A is TRUE
1788Only B is TRUE
1789Bothe A and B is TRUE
1790Both A and B is FALSE
17910
17920
17931
17940
1795Exception_handling_NewQB
1796public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } catch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); }}
1797MCQ
1798hello throwit caught finally after
1799hello throwit caught
1800hello throwit RuntimeException caught after
1801Compilation fails
18021
18030
18040
18050
1806Exception_handling_NewQB
1807class s implements Runnable { int x, y; public void run() { for(int i = 0; i < 1000; i++) synchronized(this) { x = 12; y = 12; } System.out.print(x + " " + y + " "); } public static void main(String args[]) { s run = new s(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start(); t2.start(); } } What is the output?
1808MCQ
1809DeadLock
1810Compilation Error
1811Cannot determine output.
1812prints 12 12 12 12
18130
18140
18150
18161
1817Exception_handling_NewQB
1818What 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();}}
1819MCQ
1820Since the method foo() does not catch the exception generated by the method baz(),it must declare the RuntimeException in a throws clause
1821A try block cannot be followed by both a catch and a finally block
1822An empty catch block is not allowed
1823A catch block cannot follow a finally block
1824A finally block must always follow one or more catch blocks
18250
18260
18270
18281
18290
1830Exception_handling_NewQB
1831Consider the following code and choose the correct option:class Test{static void test() throws RuntimeException { try { System.out.print("test "); throw new RuntimeException(); } catch (Exception ex) { System.out.print("exception "); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { System.out.print("runtime "); } System.out.print("end"); } }
1832MCQ
1833test end
1834test runtime end
1835test exception runtime end
1836test exception end
18370
18380
18390
18401
1841Exception_handling_NewQB
1842Choose TWO correct options:
1843MCA
1844If an exception is not caught in a method,the method will terminate and normal execution will resume
1845An overriding method must declare that it throws the same exception classes as the method it overrides
1846The main() method of a program can declare that it throws checked exception
1847A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class
1848Finally blocks are executed if,an exception gets thrown while inside the corresponding
18490
18500
18510.5
18520.5
18530
1854Exception_handling_NewQB
1855Which four can be thrown using the throw statement? 1.Error 2.Event 3.Object 4.Throwable 5.Exception 6.RuntimeException
1856MCQ
18571, 2, 3 and 4
18582, 3, 4 and 5
18591, 4, 5 and 6
18602, 4, 5 and 6
18610
18620
18631
18640
1865Exception_handling_NewQB
1866class 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 ?
1867MCQ
1868Thread t = new Thread(X);
1869Thread t = new Thread(X); t.start();
1870X run = new X(); Thread t = new Thread(run); t.start();
1871Thread t = new Thread(); x.run();
18720
18730
18741
18750
1876Exception_handling_NewQB
1877Given: class X { public void foo() { System.out.print("X "); } } public class SubB extends X { public void foo() throws RuntimeException { super.foo(); if (true) throw new RuntimeException(); System.out.print("B "); } public static void main(String[] args) { new SubB().foo(); } }What is the result?
1878MCQ
1879X, followed by an Exception.
1880No output, and an Exception is thrown.
1881X, followed by an Exception, followed by B.
1882none
18831
18840
18850
18860
1887Exception_handling_NewQB
1888What will the output of following code?try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println("Exception"); } catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); } System.out.println("finished");
1889MCQ
1890finished
1891Exception
1892compilation fails
1893ArithmeticException
18940
18950
18961
18970
1898Exception_handling_NewQB
1899Which of the following methods are static?
1900MCA
1901start()
1902join()
1903yield()
1904sleep()
19050
19060
19070.5
19080.5
1909Exception_handling_NewQB
1910Which of the following statements regarding static methods are correct? (2 answers)
1911MCA
1912static methods are difficult to maintain, because you can not change their implementation.
1913static methods can be called using an object reference to an object of the class in which this method is defined.
1914static methods are always public, because they are defined at class-level.
1915static methods do not have direct access to non-static methods which are defined inside the same class.
19160
19170.5
19180
19190.5
1920Exception_handling_NewQB
1921Consider 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){ System.out.println("caught");} finally{ System.out.println("exit");}}}}
1922MCQ
1923caught exit
1924exit
1925exit RuntimeException thrown at run time
1926Compilation fails
19270
19280
19291
19300
1931Exception_handling_NewQB
1932class Test{public static void main(String[] args){try{Integer.parseInt("1.0");}catch(Exception e){System.out.println("Exception occurred");}catch(RuntimeException ex){System.out.println("RuntimeException");}} }consider the code above & select the proper output from the options.
1933MCQ
1934Exception occurred
1935RuntimeException
1936Exception occurred RuntimeException
1937does not compile
19380
19390
19400
19411
1942Exception_handling_NewQB
1943Which three of the following are methods of the Object class? 1.notify(); 2.notifyAll(); 3.isInterrupted(); 4.synchronized(); 5.interrupt(); 6.wait(long msecs); 7.sleep(long msecs); 8.yield();
1944MCQ
19451, 2, 4
19462, 4, 5
19471, 2, 6
19482, 3, 4
19490
19500
19511
19520
1953Exception_handling_NewQB
1954In the given code snippettry { int a = Integer.parseInt("one"); }what is used to create an appropriate catch block? (Choose all that apply.)A. ClassCastExceptionB. IllegalStateExceptionC. NumberFormatExceptionD. IllegalArgumentException
1955MCA
1956ClassCastException
1957NumberFormatException
1958IllegalStateException
1959IllegalArgumentException
19600
19610.5
19620
19630.5
1964Exception_handling_NewQB
1965class Trial{public static void main(String[] args){try{System.out.println("One");int y = 2 / 0;System.out.println("Two");} catch(RuntimeException ex){System.out.println("Catch");} finally{System.out.println("Finally");}} }
1966MCQ
1967One Two Catch Finally
1968One Catch
1969One Catch Finally
1970One Two Catch
19710
19720
19731
19740
1975Exception_handling_NewQB
1976Which 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) { System.out.println("1"); }catch(RuntimeException e) { System.out.println("2"); return; }catch(Exception e) { System.out.println("3"); }finally{System.out.println("4");}System.out.println("5");}}
1977MCQ
1978The program will only print 5
1979The program will only print 1 and 4 in order
1980The program will only print 1,2 and 4 in order
1981The program will only print 1 ,4 and 5 in order
1982The program will only print 1,2,4 and 5 in order
19830
19840
19850
19861
19870
1988Exception_handling_NewQB
1989class Trial{public static void main(String[] args){try{System.out.println("Java is portable");} } }
1990MCQ
1991Java is portable
1992We cannot have a try block without a catch block
1993We cannot have a try block block without a catch / finally block
1994Nothing is diaplayed
19950
19960
19971
19980
1999Exception_handling_NewQB
2000class Animal { public String noise() { return "peep"; } } class Dog extends Animal { public String noise() { return "bark"; } } class Cat extends Animal { public String noise() { return "meow"; } }class try1{public static void main(String[] args){Animal animal = new Dog(); Cat cat = (Cat)animal; System.out.println(cat.noise());}}consider the code above & select the proper output from the options.
2001MCQ
2002bark
2003meow
2004Compilation fails
2005An exception is thrown at runtime.
2006peep
20070
20080
20090
20101
20110
2012Exception_handling_NewQB
2013Given:class X implements Runnable { public static void main(String args[]) { /* Some code */ } public void run() {} }Which of the following line of code is suitable to start a thread ?
2014MCQ
2015X run = new X(); Thread t = new Thread(run); t.start();
2016Thread t = new Thread(X);
2017Thread t = new Thread(); x.run();
2018Thread t = new Thread(X); t.start();
20191
20200
20210
20220
2023Exception_handling_NewQB
2024Which statement is true?
2025MCQ
2026A static method cannot be synchronized.
2027If a class has synchronized code, multiple threads can still access the nonsynchronized code.
2028Variables can be protected from concurrent access problems by marking them with the synchronized keyword.
2029When a thread sleeps, it releases its locks
20300
20311
20320
20330
2034Exception_handling_NewQB
2035Consider 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){ } catch(RuntimeException re){} finally{System.out.println("exit");}}}
2036MCQ
2037exit
2038Compiles and no output
2039Compilation fails
2040Compiles but exception at runtime
20410
20420
20431
20440
2045Exception_handling_NewQB
2046Given:public class ExceptionTest { class TestException extends Exception {} public void runTest() throws TestException {} public void test() /* Line X */ { runTest(); } }At Line X, which code is necessary to make the code compile?
2047MCQ
2048No code is necessary
2049throws Exception
2050throw Exception
2051throws RuntimeException
20520
20531
20540
20550
2056Exception_handling_NewQB
2057Which two can be used to create a new Thread?
2058MCA
2059Implement java.lang.Runnable and implement the run() method.
2060Extend java.lang.Thread and override the run() method.
2061Implement java.lang.Thread and implement the start() method.
2062Extend java.lang.Runnable and override the start() method.
2063Implement java.lang.Thread and implement the
20640.5
20650.5
20660
20670
20680
2069Exception_handling_NewQB
2070Choose the correct option:
2071MCQ
2072A try statement must have at least one corresponding catch block
2073Multiple catch statements can catch the same class of exception more than once.
2074An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.
2075Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.
20760
20770
20780
20791
2080Exception_handling_NewQB
2081class PropagateException{public static void main(String[] args){try{method();System.out.println("method() called");}catch(ArithmeticException ex){System.out.println("Arithmetic Exception");}catch(RuntimeException re){System.out.println("Runtime Exception");}}static void method(){int y = 2 / 0;}}consider the code above & select the proper output from the options.
2082MCQ
2083Arithmetic Exception
2084Runtime Exception
2085Arithmetic Exception Runtime Exception
2086compilation error
20871
20880
20890
20900
2091Exception_handling_NewQB
2092Given: static void test() { try { String x = null; System.out.print(x.toString() + " "); } finally { System.out.print("finally "); } } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print("exception "); } }What is the result?
2093MCQ
2094null
2095Compilation fails.
2096finally exception
2097finally
20980
20990
21001
21010
2102Exception_handling_NewQB
2103Given two programs:1. package pkgA;2. public class Abc {3. int a = 5;4. protected int b = 6;5. public int c = 7;6. }3. package pkgB;4. import pkgA.*;5. public class Def {6. public static void main(String[] args) {7. Abc f = new Abc();8. System.out.print(" " + f.a);9. System.out.print(" " + f.b);10. System.out.print(" " + f.c);11. }12. }What is the result when the second program is run? (Choose all that apply)
2104MCA
21055 6 7
21065 followed by an exception
2107Compilation fails with an error on line 7
2108Compilation fails with an error on line 8
2109Compilation fails with an error on line 9
21100
21110
21120
21130.5
21140.5
2115Exception_handling_NewQB
2116Consider the following code:System.out.print("Start ");try { System.out.print("Hello world"); throw new FileNotFoundException();}System.out.print(" Catch Here "); /* Line 7 */catch(EOFException e) { System.out.print("End of file exception");}catch(FileNotFoundException e) { System.out.print("File not found");}given that EOFException and FileNotFoundException are both subclasses of IOException. If this block of code is pasted in a method, choose the best option.
2117MCQ
2118The code will not compile.
2119Code output: Start Hello world File Not Found
2120Code output: Start Hello world End of file exception.
2121Code output: Start Hello world Catch Here File not found.
21221
21230
21240
21250
2126Exception_handling_NewQB
2127Which of the following statements is true?
2128MCQ
2129catch(X x) can catch subclasses of X where X is a subclass of Exception.
2130The Error class is a RuntimeException.
2131Any statement that can throw an Error must be enclosed in a try block.
2132Any statement that can throw an Exception must be enclosed in a try block.
21331
21340
21350
21360
2137Exception_handling_NewQB
2138Consider the following code and choose the correct option:int array[] = new int[10];array[-1] = 0;
2139MCQ
2140compiles successfully
2141does not compile
2142runtime error
2143none of the listed options
21440
21450
21461
21470
2148Exception_handling_NewQB
2149What will be the output of the program? public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } catch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); }}
2150MCQ
2151hello throwit caught
2152Compilation fails
2153hello throwit RuntimeException caught after
2154hello throwit caught finally after
21550
21560
21570
21581
2159Exception_handling_NewQB
2160What is the keyword to use when the access of a method has to be restricted to only one thread at a time
2161MCQ
2162volatile
2163synchronized
2164final
2165private
21660
21671
21680
21690
2170Exception_handling_NewQB
2171Consider the following code and choose the correct option:class Test{ public static void parse(String str) { try { int num = Integer.parseInt(str); } catch (NumberFormatException nfe) { num = 0; } finally { System.out.println(num); } } public static void main(String[] args) { parse("one"); }
2172MCQ
2173NumberFormatException thrown at runtime
2174Compilation fails
2175ParseException thrown at runtime
21760
21770
21781
21790
2180Exception_handling_NewQB
2181public static void parse(String str) {try {float f = Float.parseFloat(str);} catch (NumberFormatException nfe) {f = 0;} finally {System.out.println(f);}}public static void main(String[] args) {parse("invalid");}
2182MCQ
2183Compilation fails
2184A ParseException is thrown by the parse method at runtime.
2185A NumberFormatException is thrown by the parse method at runtime.
21860
21871
21880
21890
2190Exception_handling_NewQB
2191Given the following program,which statements are true? (Choose TWO) Public class Exception { public static void main(String[] args) { try { if(args.length == 0) return;System.out.println(args[0]);}finally {System.out.println("The end");}}}
2192MCA
2193If run with no arguments,the program will produce no output
2194If run with no arguments,the program will produce "The end"
2195The program will throw an ArrayIndexOutOfBoundsException
2196If run with one arguments,the program will simply print the given argument
2197If run with one arguments,the program will print the given argument
21980
21990.5
22000
22010
22020.5
2203Exception_handling_NewQB
2204Which can appropriately be thrown by a programmer using Java SE technology to createa desktop application?
2205MCQ
2206ClassCastException
2207NullPointerException
2208NoClassDefFoundError
2209NumberFormatException
22100
22110
22120
22131
2214Exception_handling_NewQB
2215Which of the following is a checked exception?
2216MCQ
2217Arithmetic Exception
2218IOException
2219NullPointerException
2220ArrayIndexOutOfBoundsException
22210
22221
22230
22240
2225Exception_handling_NewQB
2226Given:11. class A {12. public void process() { System.out.print("A,"); }13. class B extends A {14. public void process() throws IOException {15. super.process();16. System.out.print("B,");17. throw new IOException();18. }19. public static void main(String[] args) {20. try { new B().process(); }21. catch (IOException e) { System.out.println("Exception"); }22. }What is the result?
2227MCQ
2228Exception
2229A,B,Exception
2230Compilation fails because of an error in line 20.
2231Compilation fails because of an error in line 14.
22320
22330
22340
22351
2236Exception_handling_NewQB
2237Which statement is true?
2238MCQ
2239The notifyAll() method must be called from a synchronized context
2240To call sleep(), a thread must own the lock on the object
2241The notify() method is defined in class java.lang.Thread
2242The notify() method causes a thread to immediately release its locks.
22431
22440
22450
22460
2247Exception_handling_NewQB
2248class Trial{public static void main(String[] args){try{System.out.println("Try Block");} finally{System.out.println("Finally Block");}} }
2249MCQ
2250Try Block
2251Try Block Finally Block
2252Finally Block
2253Finally Block Try Block
22540
22551
22560
22570
2258Exception_handling_NewQB
2259consider the code & choose the correct output:class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start(); System.out.println("End of method."); } }
2260MCQ
2261java.lang.RuntimeException: Problem
2262run java.lang.RuntimeException: Problem
2263End of method. java.lang.RuntimeException: Problem
2264End of method. run. java.lang.RuntimeException: Problem
22650
22660
22670
22681
2269Exception_handling_NewQB
2270The exceptions for which the compiler doesn’t enforce the handle or declare rule
2271MCQ
2272Checked exceptions
2273Unchecked exceptions
2274Exception
2275all of these
22760
22771
22780
22790
2280Exception_handling_NewQB
2281Consider the code below & select the correct ouput from the options:public class Test{ Integer i; int x; Test(int y){ x=i+y; System.out.println(x); }public static void main(String[] args) { new Test(new Integer(5));}}
2282MCQ
22835
2284Compilation error
2285Compiles but error at run time
22860
22870
22881
22890
2290Exception_handling_NewQB
2291Given: public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); }}Which statement is true?
2292MCQ
2293Compilation fails.
2294Synchronizing the run() method would make the class thread-safe.
2295Declaring the doThings() method as static would make the class thread-safe.
2296An exception is thrown at runtime.
22970
22980
22991
23000
2301Exception_handling_NewQB
2302Consider 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){ System.out.println("caught");}System.out.println("exit");}}}
2303MCQ
2304caught exit
2305exit
2306Compilation fails
2307Compiles but exception at runtime
23080
23090
23100
23111
2312Garbage_Collection_NewQB
2313Which statements describe guaranteed behaviour of the garbage collection and finalization mechanisms? (Choose TWO)
2314MCA
2315An object is deleted as soon as there are no more references that denote the object
2316The finilize() method will eventually be called on every object
2317The finalize() method will never be called more than once on an object
2318An object will not be garbage collected as long as it possible for a live thread to access it through a reference.
2319The garbage collector will use a mark and sweep algorithm
23200
23210
23220.5
23230.5
23240
2325Garbage_Collection_NewQB
2326Which statement is true?A. A class's finalize() method CANNOT be invoked explicitly.B. super.finalize() is called implicitly by any overriding finalize() method.C. The finalize() method for a given object is called no more than once by the garbage collector.D. The order in which finalize() is called on two objects is based on the order in which the twoobjects became finalizable.
2327MCQ
2328A
2329B
2330C
2331D
23320
23330
23341
23350
2336Garbage_Collection_NewQB
2337Which of the following allows a programmer to destroy an object x?
2338MCQ
2339x.delete()
2340x.finalize()
2341Runtime.getRuntime().gc()
2342Only the garbage collection system can destroy an object.
23430
23440
23450
23461
2347Garbage_Collection_NewQB
2348class X2 { public X2 x; public static void main(String [] args) { X2 x2 = new X2(); /* Line 6 */ X2 x3 = new X2(); /* Line 7 */ x2.x = x3; x3.x = x2; x2 = new X2(); x3 = x2; /* Line 11 */ }}after line 11 runs, how many objects are eligible for garbage collection?
2349MCQ
23501
23512
23523
23530
23540
23551
23560
2357Garbage_Collection_NewQB
2358Given :public class MainOne { public static void main(String args[]) { String str = "this is java"; System.out.println(removeChar(str,'s')); } public static String removeChar(String s, char c) { String r = ""; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != c) r += s.charAt(i); } return r; } } What would be the result?
2359MCQ
2360This is java
2361Thi is java
2362This i java
2363Thi i java
2364none of the listed options
23650
23660
23670
23681
23690
2370Garbage_Collection_NewQB
2371How can you force garbage collection of an object?
2372MCQ
2373Set all references to the object to new values(null, for example).
2374Call System.gc() passing in a reference to the object to be garbage collected
2375Call System.gc()
2376Call Runtime.gc().
2377Garbage collection cannot be forced
23780
23790
23800
23810
23821
2383Garbage_Collection_NewQB
2384Consider the following code and choose the correct option:public class X { public static void main(String [] args) { X x = new X(); X x2 = m1(x); /* Line 6 */ X x4 = new X(); x2 = x4; /* Line 8 */ doComplexStuff(); } static X m1(X mx) { mx = new X(); return mx; }}After line 8 runs. how many objects are eligible for garbage collection?
2385MCQ
23861
23872
23883
23890
23901
23910
23920
2393Inheritance_Interfaces_Abstract Classes_NewQB
2394interface interface_1 { void f1();}class Class_1 implements interface_1 { void f1() { System.out.println("From F1 funtion in Class_1 Class"); }}public class Demo1 { public static void main(String args[]) { Class_1 o11 = new Class_1(); o11.f1(); }}
2395MCQ
2396From F1 function in Class_1 Class
2397Compile time error
2398Create an object for Interface only
2399Runtime Error
24000
24011
24020
24030
2404Inheritance_Interfaces_Abstract Classes_NewQB
2405Given:class A { final void meth() { System.out.println("This is a final method."); } } class B extends A { void meth() { System.out.println("Illegal!"); } } class MyClass8{ public static void main(String[] args) { A a = new A(); a.meth(); B b= new B(); b.meth(); } }What would be the result?
2406MCQ
2407This is a final method illegal
2408This is a final method Some error message
2409Compilation error
2410illegal Some error message
24110
24120
24131
24140
2415Inheritance_Interfaces_Abstract Classes_NewQB
2416Which Man class properly represents the relationship "Man has a best friend who is a Dog"?A)class Man extends Dog { }B)class Man implements Dog { }C)class Man { private BestFriend dog; }D)class Man { private Dog bestFriend; }
2417MCQ
2418A
2419B
2420C
2421D
24220
24230
24240
24251
2426Inheritance_Interfaces_Abstract Classes_NewQB
2427What will be the output of the program? class SuperClass { public Integer getLength() { return new Integer(4); } } public class SubClass extends SuperClass { public Long getLength() { return new Long(5); } public static void main(String[] args) { SuperClass sp = new SuperClass(); SubClass sb = new SubClass(); System.out.println( sp.getLength().toString() + "," + sub.getLength().toString() ); } }
2428MCQ
24294, 4
24304, 5
24315, 4
2432Compilation fails
24330
24340
24350
24361
2437Inheritance_Interfaces_Abstract Classes_NewQB
2438Consider the code below & select the correct ouput from the options:abstract class Ab{ public int getN(){return 0;}}class Bc extends Ab{ public int getN(){return 7;}}class Cd extends Bc { public int getN(){return 47;}}class Test{ public static void main(String[] args) { Cd cd=new Cd(); Bc bc=new Cd(); Ab ab=new Cd(); System.out.println(cd.getN()+" "+ bc.getN()+" "+ab.getN()); }}
2439MCQ
24400 0 0
244147 7 0
2442Compilation error
244347 47 47
24440
24450
24460
24471
2448Inheritance_Interfaces_Abstract Classes_NewQB
2449interface A{}class B implements A{}class C extends B{}public class Test extends C{public static void main(String[] args) { C c=new C(); /* Line6 */}}Which code, inserted at line 6, will cause a java.lang.ClassCastException?
2450MCQ
2451B b=c;
2452A a2=(B)c;
2453C c2=(C)(B)c;
2454A a1=(Test)c;
24550
24560
24570
24581
2459Inheritance_Interfaces_Abstract Classes_NewQB
2460Given :What would be the result of compiling and running the following program?// Filename: MyClass.javapublic class MyClass {public static void main(String[] args) {C c = new C();System.out.println(c.max(13, 29));}}class A {int max(int x, int y) { if (x>y) return x; else return y; }}class B extends A{int max(int x, int y) { return super.max(y, x) - 10; }}class C extends B {int max(int x, int y) { return super.max(x+10, y+10); }}
2461MCQ
2462The code will fail to compile because the max() method in B passes the arguments in the call super.max(y, x) in the wrong order.
2463The code will fail to compile because a call to a max() method is ambiguous.
2464The code will compile and print 23, when run.
2465The code will compile and print 29, when run.
24660
24670
24680
24691
2470Inheritance_Interfaces_Abstract Classes_NewQB
2471The concept of multiple inheritance is implemented in Java by(A) extending two or more classes(B) extending one class and implementing one or more interfaces(C) implementing two or more interfaces(D) all of these
2472MCQ
2473(A)
2474(A) & (C)
2475(D)
2476(B) & (C)
24770
24780
24790
24801
2481Inheritance_Interfaces_Abstract Classes_NewQB
2482Given:interface DoMath { double getArea(int r); }interface MathPlus { double getVolume(int b, int h); }/* Missing Statements ? */Select the correct missing statements.
2483MCQ
2484class AllMath extends DoMath { double getArea(int r); }
2485interface AllMath implements MathPlus { double getVol(int x, int y); }
2486abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.14; } }
2487class AllMath implements MathPlus { double getArea(int rad); }
24880
24890
24901
24910
2492Inheritance_Interfaces_Abstract Classes_NewQB
2493Consider the following code and choose the correct option:class A{ void display(byte a, byte b){ System.out.println("sum of byte"+(a+b)); } void display(int a, int b){ System.out.println("sum of int"+(a+b)); } public static void main(String[] args) { new A().display(3, 4); }}
2494MCQ
2495sum of byte 7
2496Compilation error
2497sum of int7
2498Compiles but error at runtime
24990
25000
25011
25020
2503Inheritance_Interfaces_Abstract Classes_NewQB
2504Consider the following code and choose the correct option:interface Output{ void display(); void show();}class Screen implements Output{ void display(){ System.out.println("display"); }public static void main(String[] args) { new Screen().display();}}
2505MCQ
2506display
2507Compilation error
2508Compiles but error at run time
2509Runs but no output
25100
25111
25120
25130
2514Inheritance_Interfaces_Abstract Classes_NewQB
2515class Animal {void makeNoise() {System.out.println("generic noise"); }}class Dog extends Animal {void makeNoise() {System.out.println("bark"); }void playDead() { System.out.println("roll over"); }}class CastTest2 {public static void main(String [] args) {Dog a = (Dog) new Animal();a.makeNoise();}}consider the code above & select the proper output from the options.
2516MCQ
2517run time error
2518generic noise
2519bark
2520compile error
25211
25220
25230
25240
2525Inheritance_Interfaces_Abstract Classes_NewQB
2526Consider the following code and choose the correct option:interface employee{ void saldetails(); void perdetails();}abstract class perEmp implements employee{ public void perdetails(){ System.out.println("per details"); }} class Programmer extends perEmp{ public void saldetails(){ perdetails(); System.out.println("sal details"); } public static void main(String[] args) { perEmp emp=new Programmer(); emp.saldetails(); }}
2527MCQ
2528sal details
2529sal details per details
2530compilation error
2531per details sal details
25320
25330
25340
25351
2536Inheritance_Interfaces_Abstract Classes_NewQB
2537Consider the code below & select the correct ouput from the options:class A{ static int sq(int n){ return n*n; }}public class Test extends A{ static int sq(int n){ return super.sq(n); } public static void main(String[] args) { System.out.println(new Test().sq(3)); }}
2538MCQ
25393
2540Compilation error
2541Compiles but error at run time
25429
25430
25441
25450
25460
2547Inheritance_Interfaces_Abstract Classes_NewQB
2548Given:public static void main( String[] args ) { SomeInterface x; ... } Can an interface name be used as the type of a variable
2549MCQ
2550No—a variable must always be an object reference type
2551No—a variable must always be an object reference type or a primitive type
2552No—a variable must always be a primitive type
2553Yes—the variable can refer to any object whose class implements the interface
25540
25550
25560
25571
2558Inheritance_Interfaces_Abstract Classes_NewQB
2559Consider the following code and choose the correct option:interface A{ int i=3;} interface B{ int i=4;}class Test implements A,B{ public static void main(String[] args) { System.out.println(i); }}
2560MCQ
25613
25624
2563compilation error
2564Compiles but error at runtime
25650
25660
25671
25680
2569Inheritance_Interfaces_Abstract Classes_NewQB
2570Given the following classes and declarations, which statements are true?// Classesclass A {private int i;public void f() { /* ... */ }public void g() { /* ... */ }}class B extends A{public int j;public void g() { /* ... */ }}// Declarations:A a = new A();B b = new B();Select the three correct answers.
2571MCA
2572The B class is a subclass of A.
2573The statement b.f(); is legal
2574The statement a.j = 5; is legal.
2575The statement a.g(); is legal
2576The statement b.i = 3; is legal.
25770.3
25780.33
25790
25800.3
25810
2582Inheritance_Interfaces_Abstract Classes_NewQB
2583Which declaration can be inserted at (1) without causing a compilation error?interface MyConstants {int r = 42;int s = 69;// (1) INSERT CODE HERE}
2584MCA
2585int total = total + r + s;
2586final double circumference = 2 * Math.PI * r;
2587protected int CODE = 31337;
2588int AREA = r * s;
2589public static MAIN = 15;
25900
25910.5
25920
25930.5
25940
2595Inheritance_Interfaces_Abstract Classes_NewQB
2596What is the output for the following code:abstract class One{private abstract void test();}class Two extends One{void test(){System.out.println("hello");}}class Test{public static void main(String[] args){Two obj = new Two();obj.test();}}
2597MCQ
2598run time exception
2599compile time error
2600hello
2601hellohello
26020
26031
26040
26050
2606Inheritance_Interfaces_Abstract Classes_NewQB
2607Consider the code below & select the correct ouput from the options:class Money {private String country = "Canada"; public String getC() { return country; } } class Yen extends Money { public String getC() { return super.country; } public static void main(String[] args) { System.out.print(new Yen().getC() ); } }
2608MCQ
2609Canada
2610Compilation error
2611Compiles but error at run time
2612null
26130
26141
26150
26160
2617Inheritance_Interfaces_Abstract Classes_NewQB
2618When we use both implements & extends keywords in a single java program then what is the order of keywords to follow?
2619MCQ
2620we must use always extends and later we must use implements keyword.
2621we must use always implements and later we must use extends keyword.
2622we can use in any order its not at all a problem
2623extends and implements can't be used together
26241
26250
26260
26270
2628Inheritance_Interfaces_Abstract Classes_NewQB
2629Consider the code below & select the correct ouput from the options:1. public class Mountain {2. protected int height(int x) { return 0; }3. }4. class Alps extends Mountain {5. // insert code here6. }Which five methods, inserted independently at line 5, will compile? (Choose three.)A. public int height(int x) { return 0; }B. private int height(int x) { return 0; }C. private int height(long x) { return 0; }D. protected long height(long x) { return 0; }E. protected long height(int x) { return 0; }
2630MCQ
2631A,B,E
2632A,C,D
2633B,D,E
2634C,D,E
26350
26361
26370
26380
2639Inheritance_Interfaces_Abstract Classes_NewQB
2640Given: interface DeclareStuff { public static final int Easy = 3;void doStuff(int t); }public class TestDeclare implements DeclareStuff { public static void main(String [] args) {int x = 5; new TestDeclare().doStuff(++x);} void doStuff(int s) { s += Easy + ++s;System.out.println("s " + s); }} What is the result?
2641MCQ
2642s 14
2643s 16
2644s 10
2645Compilation fails.
26460
26470
26480
26491
2650Inheritance_Interfaces_Abstract Classes_NewQB
2651Given:interface A { public void methodA(); }interface B { public void methodB(); }interface C extends A,B{ public void methodC(); } //Line 3class D implements B {public void methodB() { } //Line 5}class E extends D implements C { //Line 7public void methodA() { }public void methodB() { } //Line 9public void methodC() { }}What would be the result?
2652MCQ
2653Compilation fails, due to an error in line 3
2654If you define D e = (D) (new E()), then e.methodB() invokes the version of methodB() defined at line 9
2655Compilation fails, due to an error in line 7
2656If you define D e = (D) (new E()), then e.methodB() invokes the version of methodB() defined at line 5
26570
26581
26590
26600
2661Inheritance_Interfaces_Abstract Classes_NewQB
2662Which of the following statements is true regarding the super() method?
2663MCQ
2664It can only be used in the parent's constructor
2665Only one child class can use it
2666It must be used in the last statement of the constructor.
2667It must be used in the first statement of the constructor.
26680
26690
26700
26711
2672Inheritance_Interfaces_Abstract Classes_NewQB
2673Consider the following code and choose the correct option:interface Output{ void display(); void show();}class Screen implements Output{ void show() {System.out.println("show");} void display(){ System.out.println("display"); }public static void main(String[] args) { new Screen().display();}}
2674MCQ
2675display
2676Compilation error
2677Compiles but error at run time
2678Runs but no output
26790
26801
26810
26820
2683Inheritance_Interfaces_Abstract Classes_NewQB
2684Consider the following code and choose the correct option:class A{ void display(){ System.out.println("Hello A"); }}class B extends A{ void display(){ System.out.println("Hello B"); }}public class Test { public static void main(String[] args) { B b=(B) new A(); b.display(); }}
2685MCQ
2686Hello A
2687Compilation error
2688Hello B
2689Compiles but error at runtime
26900
26910
26920
26931
2694Inheritance_Interfaces_Abstract Classes_NewQB
2695Consider the following code: // Class declarations:class Super {}class Sub extends Super {}// Reference declarations:Super x;Sub y;Which of the following statements is correct for the code: y = (Sub) x?
2696MCQ
2697Illegal at compile time
2698Legal at compile time, but might be illegal at runtime
2699Definitely legal at runtime, but the cast operator (Sub) is not strictly needed.
2700Definitely legal at runtime, and the cast operator (Sub) is needed.
27010
27021
27030
27040
2705Inheritance_Interfaces_Abstract Classes_NewQB
2706Given:11. class ClassA {}12. class ClassB extends ClassA {}13. class ClassC extends ClassA {}and:21. ClassA p0 = new ClassA();22. ClassB p1 = new ClassB();23. ClassC p2 = new ClassC();24. ClassA p3 = new ClassB();25. ClassA p4 = new ClassC();Which TWO are valid? (Choose two.)
2707MCA
2708p0 = p1;
2709p2 = p4;
2710p1 = (ClassB)p3;
2711p1 = p2;
27120.5
27130
27140.5
27150
2716Inheritance_Interfaces_Abstract Classes_NewQB
2717Consider the following code and choose the correct option:abstract class Car{ abstract void accelerate(); }class Lamborghini extends Car{ @Override void accelerate() { System.out.println("90 mph"); } void nitroBooster(){ System.out.print("150 mph"); } public static void main(String[] args) { Car mycar=new Lamborghini(); Lamborghini lambo=(Lamborghini) mycar; lambo.nitroBooster();}}
2718MCQ
2719150 mph
2720Compilation error
272190 mph
2722Compiles but error at runtime
27231
27240
27250
27260
2727Inheritance_Interfaces_Abstract Classes_NewQB
2728Consider the following code and choose the correct option:class A{ void display(){ System.out.println("Hello A"); }}class B extends A{ void display(){ System.out.println("Hello B"); }}public class Test { public static void main(String[] args) { A a=new B(); B b= (B)a; b.display(); }}
2729MCQ
2730Hello A
2731Compilation error
2732Hello B
2733Compiles but error at runtime
27340
27350
27361
27370
2738Inheritance_Interfaces_Abstract Classes_NewQB
2739A class Animal has a subclass Mammal. Which of the following is true:
2740MCQ
2741Because of single inheritance, Mammal can have no subclasses
2742Because of single inheritance, Mammal can have no other parent than Animal
2743Because of single inheritance, Animal can have only one subclass
2744Because of single inheritance, Mammal can have no siblings.
27450
27461
27470
27480
2749Inheritance_Interfaces_Abstract Classes_NewQB
2750class Animal {void makeNoise() {System.out.println("generic noise"); }}class Dog extends Animal {void makeNoise() {System.out.println("bark"); }void playDead() { System.out.println("roll over"); }}class CastTest2 {public static void main(String [] args) {Animal a = new Dog();a.makeNoise();}}consider the code above & select the proper output from the options.
2751MCQ
2752run time error
2753generic noise
2754bark
2755compile error
27560
27570
27581
27590
2760Inheritance_Interfaces_Abstract Classes_NewQB
2761What will be the result when you try to compile and run the following code? class Base1 { Base1() { int i = 100; System.out.println(i); }}public class Pri1 extends Base1 { static int i = 200; public static void main(String argv[]) { Pri1 p = new Pri1(); System.out.println(i); }}
2762MCQ
2763Error at compile time
2764200
2765100 followed by 200
2766100
27670
27680
27691
27700
2771Inheritance_Interfaces_Abstract Classes_NewQB
2772What is the output :interface A{void method1();void method2();}class Test implements A{public void method1(){System.out.println("hello");}}class RunTest{public static void main(String[] args){Test obj = new Test();obj.method1();}}
2773MCQ
2774hello
2775compile error
2776runtime error
2777none
27780
27791
27800
27810
2782Inheritance_Interfaces_Abstract Classes_NewQB
2783Given the following classes and declarations, which statements are true?// Classesclass Foo {private int i;public void f() { /* ... */ }public void g() { /* ... */ }}class Bar extends Foo {public int j;public void g() { /* ... */ }}// Declarations:Foo a = new Foo();Bar b = new Bar();
2784MCA
2785The Bar class is a subclass of Foo.
2786The statement a.j = 5; is legal.
2787The statement b.f(); is legal.
2788The statement a.g(); is legal.
27890.3
27900
27910.3
27920.3
2793Inheritance_Interfaces_Abstract Classes_NewQB
2794Given a derived class method which overrides one of it’s base class methods. With derived class object you can invoke the overridden base method using:
2795MCQ
2796super keyword
2797this keyword
2798by creating an instance of the base class
2799cannot call because it is overridden in derived class
28001
28010
28020
28030
2804Inheritance_Interfaces_Abstract Classes_NewQB
2805Consider the following code and choose the correct option:abstract class Car{ abstract void accelerate(); }class Lamborghini extends Car{ @Override void accelerate() { System.out.println("90 mph"); } void nitroBooster(){ System.out.print("150 mph"); } public static void main(String[] args) { Car mycar=new Lamborghini(); mycar.nitroBooster(); }}
2806MCQ
2807Compilation error
2808Compiles but error at run time
280990 mph
2810150 mph
28111
28120
28130
28140
2815Inheritance_Interfaces_Abstract Classes_NewQB
2816Given: class Pizza { java.util.ArrayList toppings; public final void addTopping(String topping) { toppings.add(topping); } } public class PepperoniPizza extends Pizza { public void addTopping(String topping) { System.out.println("Cannot add Toppings"); } public static void main(String[] args) { Pizza pizza = new PepperoniPizza(); pizza.addTopping("Mushrooms"); } }What is the result?
2817MCQ
2818Compilation fails.
2819Cannot add Toppings
2820The code runs with no output.
2821A NullPointerException is thrown
28221
28230
28240
28250
2826Inheritance_Interfaces_Abstract Classes_NewQB
2827Consider the following code and choose the correct option:interface console{ int line=10; void print();}class a implements console{ void print(){ System.out.print("A");} public static void main(String ar[]){ new a().print();}}
2828MCQ
2829A
2830Compilation error
2831Compiles but error at run time
2832Runs but no output
28330
28341
28350
28360
2837Inheritance_Interfaces_Abstract Classes_NewQB
2838Which of these field declarations are legal in an interface? (Choose all applicable)
2839MCA
2840public int answer = 42;
2841final static int answer = 42;
2842private final static int answer = 42;
2843int answer;
2844public static int answer = 42;
28450.3
28460.25
28470.3
28480
28490.25
2850Inheritance_Interfaces_Abstract Classes_NewQB
2851Given : Day d;BirthDay bd = new BirthDay("Raj", 25);d = bd; // Line XWhere Birthday is a subclass of Day. State whether the code given at Line X is correct:
2852MCQ
2853No—there must always be an exact match between the variable and the object
2854No—but a object of parent type can be assigned to a variable of child type.
2855Yes—an object can be assigned to a reference variable of the parent type.
2856Yes—any object can be assigned to any reference variable.
28570
28580
28591
28600
2861Inheritance_Interfaces_Abstract Classes_NewQB
2862Select the correct statement:
2863MCQ
2864A super() or this() call must always be provided explicitly as the first statement in the body of a constructor.
2865If both a subclass and its superclass do not have any declared constructors, the implicit default constructor of the subclass will call super() when run
2866If neither super() nor this() is declared as the first statement in the body of a constructor, this() will implicitly be inserted as the first statement.
2867If super() is the first statement in the body of a constructor, this() can be declared as the second statement
2868Calling super() as the first statement in the body of a constructor of a subclass will always
28690
28701
28710
28720
28730
2874Inheritance_Interfaces_Abstract Classes_NewQB
2875Choose the correct declaration of variable in an interface:
2876MCQ
2877public final data type varaibale=intialization;
2878static data type variable;
2879static final data type varaiblename;
2880final data type variablename=intialization;
28811
28820
28830
28840
2885Inheritance_Interfaces_Abstract Classes_NewQB
2886Consider the following code and choose the correct option:abstract class Fun{ void time(){ System.out.println("Fun Time"); }}class Run extends Fun{ void time(){ System.out.println("Fun Run"); } public static void main(String[] args) { Fun f1=new Run(); f1.time(); }}
2887MCQ
2888Fun Time
2889Compilation error
2890Fun Run
2891Compiles but error at runtime
28920
28930
28941
28950
2896Inheritance_Interfaces_Abstract Classes_NewQB
2897interface Vehicle{void drive();}final class TwoWheeler implements Vehicle{int wheels = 2;public void drive(){System.out.println("Bicycle");}}class ThreeWheeler extends TwoWheeler{public void drive(){System.out.println("Auto");}}class Test{public static void main(String[] args){ThreeWheeler obj = new ThreeWheeler();obj.drive();}}consider the code above & select the proper output from the options.
2898MCQ
2899Auto
2900Bicycle Auto
2901compile error
2902runtime error
29030
29040
29051
29060
2907Inheritance_Interfaces_Abstract Classes_NewQB
2908Consider the following code and choose the correct option:interface employee{ void saldetails(); void perdetails();}abstract class perEmp implements employee{ public void perdetails(){ System.out.println("per details"); }} class Programmer extends perEmp{ public static void main(String[] args) { perEmp emp=new Programmer(); emp.saldetails(); }}
2909MCQ
2910sal details
2911sal details per details
2912compilation error
2913per details sal details
29140
29150
29161
29170
2918Inheritance_Interfaces_Abstract Classes_NewQB
2919All data members in an interface are by default
2920MCQ
2921abstract and final
2922public and abstract
2923public ,static and final
2924default and abstract
29250
29260
29271
29280
2929Inheritance_Interfaces_Abstract Classes_NewQB
2930Consider the following code and choose the correct option:interface console{ int line; void print();}class a implements console{ public void print(){ System.out.print("A");} public static void main(String ar[]){ new a().print();}}
2931MCQ
2932A
2933Compilation error
2934Compiles but error at run time
2935Runs but no output
29360
29371
29380
29390
2940Inheritance_Interfaces_Abstract Classes_NewQB
2941Which of the following is correct for an abstract class. (Choose TWO)
2942MCA
2943An abstract class is one which contains general purpose methods
2944An abstract class is one which contains some defined methods and some undefined methods
2945An abstract class is one which contains only static methods
2946Abstract class can be declared final
29470.5
29480.5
29490
29500
2951Inheritance_Interfaces_Abstract Classes_NewQB
2952Which of the following defines a legal abstract class?
2953MCQ
2954class Vehicle { abstract void display(); }
2955abstract Vehicle { abstract void display(); }
2956class abstract Vehicle { abstract void display(); }
2957abstract class Vehicle { abstract void display(); { System.out.println("Car"); }}
2958abstract class Vehicle { abstract void display(); }
29590
29600
29610
29620
29631
2964Inheritance_Interfaces_Abstract Classes_NewQB
2965Consider the code below & select the correct ouput from the options:class Mountain{ int height; protected Mountain(int x) { height=x; } public int getH(){return height;}}class Alps extends Mountain{ public Alps(int h){ super(h); } public Alps(){ this(100); } public static void main(String[] args) { System.out.println(new Alps().getH()); }}
2966MCQ
2967100
2968Compilation error
2969Compiles but error at run time
2970Compiles but no output
29711
29720
29730
29740
2975Inheritance_Interfaces_Abstract Classes_NewQB
2976Consider the given code and select the correct output: class SomeException {}class A {public void doSomething() { }}class B extends A {public void doSomething() throws SomeException { }}
2977MCQ
2978Compilation of both classes A & B will fail
2979Compilation of both classes will succeed
2980Compilation of class A will fail. Compilation of class B will succeed
2981Compilation of class B will fail. Compilation of class A will succeed
29820
29830
29840
29851
2986Inheritance_Interfaces_Abstract Classes_NewQB
2987Is it possible if a class definition implements two interfaces, each of which has the same definition for the constant?
2988MCQ
2989No—if a class implements several interfaces, each constant must be defined in only one interface
2990No—a class may not implement more than one interface
2991Yes— either of the two variables can be accessed through : interfaceName.variableName
2992Yes—since the definitions are the same it will not matter
29930
29940
29951
29960
2997Inheritance_Interfaces_Abstract Classes_NewQB
2998Select the correct statement:
2999MCQ
3000Private methods cannot be overridden in subclasses
3001A subclass can override any method in a superclass
3002An overriding method can declare that it throws checked exceptions that are not thrown by the method it is overriding
3003The parameter list of an overriding method can be a subset of the parameter list of the method that it is overriding
3004The overriding method must have different return type as the overridden
30051
30060
30070
30080
30090
3010Inheritance_Interfaces_Abstract Classes_NewQB
3011Consider the following code and choose the correct option:class A{ void display(){ System.out.println("Hello A"); }}class B extends A{ void display(){ System.out.println("Hello B"); }}public class Test { public static void main(String[] args) { A a=new B(); B b= a; b.display(); }}
3012MCQ
3013Hello A
3014Compilation error
3015Hello B
3016Compiles but error at runtime
30170
30181
30190
30200
3021Introduction_to_Java_and_SDE_NewQB
3022Which of the following option gives one possible use of the statement 'the name of the public class should match with its file name'?
3023MCQ
3024To maintain the uniform standard
3025Helps the compiler to find the source file that corresponds to a class, when it does not find a class file while compiling
3026Helps JVM to find and execute the classes
3027Helps Javadoc to build the Java Documentation easily
30280
30291
30300
30310
3032Introduction_to_Java_and_SDE_NewQB
3033Which of the following statement gives the use of CLASSPATH?
3034MCQ
3035Holds the location of Core Java Class Library (Bootstrap classes)
3036Holds the location of Java Extension Library
3037Holds the location of User Defined classes, packages and JARs
3038Holds the location of Java Software
30390
30400
30411
30420
3043Introduction_to_Java_and_SDE_NewQB
3044Which of the following are true about packages? (Choose 2)
3045MCA
3046Packages can contain only Java Source files
3047Packages can contain both Classes and Interfaces (Compiled Classes)
3048Packages can contain non-java elements such as images, xml files etc.
3049Sub packages should be declared as private in order to deny importing them
3050Class and Interfaces in the sub packages will be automatically available to the outer
30510
30520.5
30530.5
30540
30550
3056Introduction_to_Java_and_SDE_NewQB
3057Which of the following options give the valid argument types for main() method? (Choose 2)
3058MCA
3059String [][]args
3060String args
3061String[] args[]
3062String[] args
3063String args[]
30640
30650
30660
30670.5
30680.5
3069Introduction_to_Java_and_SDE_NewQB
3070Which of the following options give the valid package names? (Choose 3)
3071MCA
3072dollorpack.$pack.$$pack
3073$$.$$.$$
3074_score.pack.__pack
3075p@ckage.subp@ckage.innerp@ckage
3076.package.subpackage.innerpa
30770.3
30780.33
30790.3
30800
30810
3082Introduction_to_Java_and_SDE_NewQB
3083Which of the following statements are true regarding java.lang.Object class? (Choose 2)
3084MCA
3085Object class is an abstract class
3086Object class cannot be instantiated directly
3087Object class has the core methods for thread synchronization
3088Object class provides the method for Set implementation in Collection framework
3089Object class implements Serializable interface internall
30900
30910
30920.5
30930.5
30940
3095Introduction_to_Java_and_SDE_NewQB
3096The term 'Java Platform' refers to ________________.
3097MCQ
3098Java Compiler (Javac)
3099Java Runtime Environment (JRE)
3100Java Database Connectivity (JDBC)
3101Java Debugger
31020
31031
31040
31050
3106JDBC_NewQB
3107Which of the following methods are needed for loading a database driver in JDBC?
3108MCQ
3109registerDriver() method
3110Class.forName()
3111registerDriver() method and Class.forName()
3112getConnection
31130
31140
31151
31160
3117JDBC_NewQB
3118how to register driver class in the memory?
3119MCQ
3120Using forName() which is a static method
3121Using the static method registerDriver() method which is available in DriverManager Class.
3122Either forName() or registerDriver()
3123None of the given options
31240
31250
31261
31270
3128JDBC_NewQB
3129Give Code snipet:{// SomecodeResultSet rs = st.executeQuery("SELECT * FROM survey"); while (rs.next()) { String name = rs.getString("name"); System.out.println(name); } rs.close();// somecode} What should be imported related to ResultSet?
3130MCQ
3131java.sql.ResultSet
3132java.sql.Driver
3133java.sql.DriverManager
3134java.sql.Connection
31351
31360
31370
31380
3139JDBC_NewQB
3140Consider the following code & select the correct option for output.String sql ="select empno,ename from emp"; PreparedStatement pst=cn.prepareStatement(sql); System.out.println(pst.toString()); ResultSet rs=pst.executeQuery(); System.out.println(rs.getString(1)+ " "+rs.getString(2));
3141MCQ
3142will show first employee record
3143Compilation error
3144Compiles but error at run time
3145Compiles but no output
31460
31470
31481
31490
3150JDBC_NewQB
3151Which of the following methods finds the maximum number of connections that a specific driver can obtain?
3152MCQ
3153Connection.getMaxConnections
3154ResultSetMetaData.getMaxConnections
3155DatabaseMetaData.getMaxConnections
3156Database.getMaxConnections
31570
31580
31591
31600
3161JDBC_NewQB
3162By default all JDBC transactions are autocommit. State TRUE/FALSE.
3163MCQ
3164true
3165false
31661
31670
3168JDBC_NewQB
3169getConnection() is method available in?
3170MCQ
3171DriverManager Class
3172Driver Interface
3173ResultSet Interface
3174Statement Interface
3175PreparedStatement Interfac
31761
31770
31780
31790
31800
3181JDBC_NewQB
3182A) By default, all JDBC transactions are auto commitB) PreparedStatement suitable for dynamic sql and requires one time compilationC) with JDBC it is possible to fetch information about the database
3183MCQ
3184Only A and B is TRUE
3185Only B and C is True
3186Both A and C is TRUE
3187All are TRUE
31880
31890
31900
31911
3192JDBC_NewQB
3193What is the use of wasNull() in ResultSet interface?
3194MCQ
3195There is no such method in ResultSet interface
3196It returns true when last read column contain SQL NULL else returns false
3197It returns int value as mentioned below: > 0 if many columns Contain Null Value < 0 if no column contains Null Value = 0 if one column contains Null value
3198none of the listed options
31990
32001
32010
32020
3203JDBC_NewQB
3204Given :public class MoreEndings { public static void main(String[] args) throws Exception { Class driverClass = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");DriverManager.registerDriver((Driver) driverClass.newInstance());// Some code} Inorder to compile & execute this code, what should we import?
3205MCQ
3206java.sql.Driver
3207java.sql.Driver
3208java.sql.Driver java.sql.DriverManager
3209java.sql.DataSource
32100
32110
32121
32130
3214JDBC_NewQB
3215Which of the following method can be used to execute to execute all type of queries i.e. either Selection or Updation SQL Queries?
3216MCQ
3217executeAll()
3218executeAllSQL()
3219execute()
3220executeQuery()
3221executeUpdate()
32220
32230
32241
32250
32260
3227JDBC_NewQB
3228Which method will return boolean when we try to execute SQL Query from a JDBC program?
3229MCQ
3230executeUpdate()
3231executeSQL()
3232execute()
3233executeQuery()
32340
32350
32361
32370
3238JDBC_NewQB
3239Cosider the following code & select the correct output.String sql ="select rollno, name from student"; PreparedStatement pst=cn.prepareStatement(sql); System.out.println(pst.toString()); ResultSet rs=pst.executeQuery(); while(rs.next()){ System.out.println(rs.getString(3)); }
3240MCQ
3241will show only name
3242Compilation error
3243will show city
3244Compiles but error at run time
32450
32460
32470
32481
3249JDBC_NewQB
3250It is possible to insert/update record in a table by using ResultSet. State TRUE/FALSE
3251MCQ
3252true
3253false
32541
32550
3256JDBC_NewQB
3257What is the default type of ResultSet in JDBC applications?
3258MCQ
3259Read Only, Forward Only
3260Updatable, Forward only
3261Read only, Scroll Sensitive
3262Updatable, Scroll sensitive
32631
32640
32650
32660
3267JDBC_NewQB
3268An application can connect to different Databases at the same time. State TRUE/FALSE.
3269MCQ
3270true
3271false
32721
32730
3274JDBC_NewQB
3275A) It is not possible to execute select query with execute() methodB) CallableStatement can executes store procedures only but not functions
3276MCQ
3277Both A and B is FALSE
3278Only A is TRUE
3279Only B is TRUE
3280Both A and B is TRUE
32811
32820
32830
32840
3285JDBC_NewQB
3286A) When one use callablestatement, in that case only parameters are send over network not sql query. B) In preparestatement sql query will compile for first time only
3287MCQ
3288Both A and B is FALSE
3289Both A and B is TRUE
3290Only A is TRUE
3291Only B is TRUE
32920
32931
32940
32950
3296JDBC_NewQB
3297Consider the code below & select the correct ouput from the options:String sql ="select * from ?"; String table=" txyz "; PreparedStatement pst=cn.prepareStatement(sql); pst.setString(1,table ); ResultSet rs=pst.executeQuery(); while(rs.next()){ System.out.println(rs.getString(1)); }
3298MCQ
3299will show all row of first column
3300Compilation error
3301Compiles but error at run time
3302Compiles but run without output
33030
33040
33051
33060
3307JDBC_NewQB
3308Sylvy wants to develop Student management system, which requires frequent insert operation about student details. In order to insert student record which statement interface will give good performance
3309MCQ
3310Statement
3311CallableStatement
3312PreparedStatement
3313RowSet
33140
33150
33161
33170
3318JDBC_NewQB
3319class CreateFile{public static void main(String[] args) {try {File directory = new File("c"); //Line 13File file = new File(directory,"myFile");if(!file.exists()) {file.createNewFile(); //Line 16}}catch(IOException e) {e.printStackTrace }}}}If the current direcory does not consists of directory "c", Which statements are true ? (Choose TWO)
3320MCA
3321Line 16 is never executed
3322An exception is thrown at runtime
3323Line 13 creates a File object named “câ€
3324Line 13 creates a directory named “c†in the file system.
33250
33260.5
33270.5
33280
3329JDBC_NewQB
3330Which of the following options contains only JDBC interfaces?
3331MCQ
33321) Driver 2) Connection 3) ResultSet 4) DriverManager 5) Class
33331) Driver 2) Connection 3) ResultSet 4) ResultSetMetaData 5) Statement 6) DriverManager 7) PreparedStatement 8) Callablestatement 9) DataBaseMetaData
33341) Driver 2) Connection 3) ResultSet 4) ResultSetMetaData 5) Statement 6) PreparedStatement 7) Callablestatement 8) DataBaseMetaData
3335All of the given options
33360
33370
33381
33390
3340Keywords_variables_operators_datatypes_NewQB
3341Consider the code below & select the correct ouput from the options: public class Test { public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); }
3342MCQ
33432 3
33441 3
33452
33463
33471
33480
33490
33500
3351Keywords_variables_operators_datatypes_NewQB
3352Which three are legal array declarations? (Choose THREE)
3353MCA
3354int [] myScores [];
3355char [] myChars;
3356int [6] myScores;
3357Dog myDogs [];
3358Dog myDogs [7];
33590.3
33600.33
33610
33620.3
33630
3364Keywords_variables_operators_datatypes_NewQB
3365Consider the given code and select the correct output:class Test{ public static void main(String[] args){ int num1 = 012; int num2 = 0x110; int sum =num1+=num2; System.out.println("Ans = "+sum); }}
3366MCQ
336726
3368282
3369Compiles but error at run time
3370Compilation error
33710
33721
33730
33740
3375Keywords_variables_operators_datatypes_NewQB
3376Say that class Rodent has a child class Rat and another child class Mouse. Class Mouse has a child class PocketMouse. Examine the following Rodent rod;Rat rat = new Rat();Mouse mos = new Mouse();PocketMouse pkt = new PocketMouse();Which one of the following will cause a compiler error?
3377MCQ
3378rod = mos
3379pkt = rat
3380pkt = null
3381rod = rat
33820
33831
33840
33850
3386Keywords_variables_operators_datatypes_NewQB
3387Consider the code below & select the correct ouput from the options:class Test{ public static void main(String[] args) { parse("Four"); } static void parse(String s){ try { double d=Double.parseDouble(s); }catch(NumberFormatException nfe){ d=0.0; }finally{ System.out.println(d); } }}
3388MCQ
3389Compilation error
3390A ParseException is thrown by the parse method at runtime
3391A NumberFormatException is thrown by the parse method at runtime
33920
33931
33940
33950
3396Keywords_variables_operators_datatypes_NewQB
3397Consider the code below & select the correct ouput from the options:class A{ public int a=7; public void add(){ this.a+=2; System.out.print("a"); }}public class Test extends A{ public int a=2; public void add(){ this.a+=2; System.out.print("t"); } public static void main(String[] args) { A a =new Test(); a.add(); System.out.print(a.a); }}
3398MCQ
3399t 7
3400t 9
3401a 9
3402Compilation error
34031
34040
34050
34060
3407Keywords_variables_operators_datatypes_NewQB
3408What will be the output of the program? public class CommandArgsTwo { public static void main(String [] argh) { int x; x = argh.length; for (int y = 1; y <= x; y++) { System.out.print(" " + argh[y]); } }}and the command-line invocation is > java CommandArgsTwo 1 2 3
3409MCQ
34100 1 2
34112 3
34120 0 0
3413An exception is thrown at runtime
34140
34150
34160
34171
3418Keywords_variables_operators_datatypes_NewQB
3419What will be the result of the following program?public class Init {String title;boolean published;static int total;static double maxPrice;public static void main(String[] args) {Init initMe = new Init();double price;if (true)price = 100.00;System.out.println("|" + initMe.title + "|" + initMe.published + "|" +Init.total + "|" + Init.maxPrice + "|" + price+ "|");}}
3420MCQ
3421The program will compile, and print |null|false|0|0.0|0.0|, when run
3422The program will compile, and print |null|true|0|0.0|100.0|, when run
3423The program will compile, and print | |false|0|0.0|0.0|, when run
3424The program will compile, and print |null|false|0|0.0|100.0|, when run
3425Compilation error
34260
34270
34280
34291
34300
3431Keywords_variables_operators_datatypes_NewQB
3432Here is the general syntax for method definition: accessModifier returnType methodName( parameterList ){ Java statements return returnValue;}What is true for the returnType and the returnValue?
3433MCQ
3434The returnValue must be exactly the same type as the returnType
3435The returnValue can be any type, but will be automatically converted to returnType when the method returns to the caller.
3436If the returnType is void then the returnValue can be any type
3437The returnValue must be the same type as the returnType, or be of a type that can be converted to returnType without loss of information.
34380
34390
34400
34411
3442Keywords_variables_operators_datatypes_NewQB
3443Consider the following code and choose the correct option:class Test{ class A{ static int x=3; } static void display(){ System.out.println(A.x); } public static void main(String[] args) { display(); }}
3444MCQ
34453
3446Compilation error
3447Compiles but error at run time
34480
34491
34500
34510
3452Keywords_variables_operators_datatypes_NewQB
3453Which of the following lines of code will compile without warning or error? 1) float f=1.3; 2) char c="a"; 3) byte b=257; 4) boolean b=null; 5) int i=10;
3454MCQ
3455Line 3
3456Line 1, Line 3, Line 5
3457Line 1, Line 5
3458Line 4
3459Line 5
34600
34610
34620
34630
34641
3465Keywords_variables_operators_datatypes_NewQB
3466Consider the following code and choose the correct option: class Test{ interface Y{ void display(); } public static void main(String[] args) { new Y(){ public void display(){ System.out.println("Hello World"); } }.display(); }}
3467MCQ
3468Hello World
3469Compilation error
3470Compiles but error at run time
3471Compiles but run without output
34721
34730
34740
34750
3476Keywords_variables_operators_datatypes_NewQB
3477Consider the following code and choose the correct option:class Test{ static class A{ interface X{ int z=4; } } static void display(){ System.out.println(A.X.z); } public static void main(String[] args) { display(); }}
3478MCQ
34794
3480Compilation error
3481Compiles but error at run time
34821
34830
34840
34850
3486Keywords_variables_operators_datatypes_NewQB
3487What is the output of the following program?public class MyClass{public static void main( String[] args ){private static final int value =9;float total;total = value + value / 2;System.out.println( total );}}
3488MCQ
348913
349013.5
349113
3492Compilation Error
3493Runtime Error
34940
34950
34960
34971
34980
3499Keywords_variables_operators_datatypes_NewQB
3500Which of the given options is similar to the following code: value += sum++ ;
3501MCQ
3502value = value + sum; sum = sum + 1;
3503sum = sum + 1; value = value + sum;
3504value = value + sum;
3505value = value + ++sum;
35061
35070
35080
35090
3510Keywords_variables_operators_datatypes_NewQB
3511What will happen if you attempt to compile and run the following code? Integer ten=new Integer(10);Long nine=new Long (9);System.out.println(ten + nine);int i=1;System.out.println(i + ten);
3512MCQ
351319 followed by 11
351419 follwed by 20
3515Compile time error
351610 followed by 1
35171
35180
35190
35200
3521Keywords_variables_operators_datatypes_NewQB
3522Identify the statements that are correct:(A) int a = 13, a>>2 = 3(B) int b = -8, b>>1 = -4(C) int a = 13, a>>>2 = 3(D) int b = -8, b>>>1 = -4
3523MCQ
3524(A), (B) & (C)
3525(A), (B), (C) & (D)
3526(C) & (D)
3527(A) & (B)
35281
35290
35300
35310
3532Keywords_variables_operators_datatypes_NewQB
3533Consider the following code: int x, y, z;y = 1;z = 5;x = 0 - (++y) + z++;After execution of this, what will be the values of x, y and z?
3534MCQ
3535x = -7, y = 1, z = 5
3536x = 3, y = 2, z = 6
3537x = 4, y = 1, z = 5
3538x = 4, y = 2, z = 6
35390
35401
35410
35420
3543Keywords_variables_operators_datatypes_NewQB
3544Here is the general syntax for method definition: accessModifier returnType methodName( parameterList ){ Java statements return returnValue;}What is true for the accessModifier?
3545MCQ
3546It must always be private or public
3547It can be omitted, but if not omitted there are several choices, including private and public
3548The access modifier must agree with the type of the return value
3549It can be omitted, but if not omitted it must be private or public
35500
35511
35520
35530
3554Keywords_variables_operators_datatypes_NewQB
3555What will be the output of the program? public class CommandArgs { public static void main(String [] args) { String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); }}and the command-line invocation is > java CommandArgs 1 2 3 4
3556MCQ
3557args[2] = 2
3558args[2] = 3
3559args[2] = null
3560An exception is thrown at runtime
35610
35620
35630
35641
3565Keywords_variables_operators_datatypes_NewQB
3566Consider the following code snippet: int i = 10;int n = ++i%5;What are the values of i and n after the code is executed?
3567MCQ
356810, 1
356911, 1
357010, 0
357111 , 0
35720
35731
35740
35750
3576Keywords_variables_operators_datatypes_NewQB
3577Which will legally declare, construct, and initialize an array?
3578MCQ
3579int [] myList = {"1", "2", "3"};
3580int [] myList = (5, 8, 2);
3581int myList [] [] = {4,9,7,0};
3582int myList [] = {4, 3, 7};
35830
35840
35850
35861
3587Keywords_variables_operators_datatypes_NewQB
3588Consider the code below & select the correct ouput from the options:public class Test { public static void main(String[] args) { int x=5; Test t=new Test(); t.disp(x); System.out.println("main X="+x); }void disp(int x) { System.out.println("disp X = "+x++); }}
3589MCQ
3590disp X = 6 main X=6
3591disp X = 5 main X=5
3592disp X = 5 main X=6
3593Compilation error
35940
35951
35960
35970
3598Keywords_variables_operators_datatypes_NewQB
3599How many objects and reference variables are created by the following lines of code?Employee emp1, emp2;emp1 = new Employee() ;Employee emp3 = new Employee() ;
3600MCQ
3601Two objects and three reference variables.
3602Three objects and two reference variables
3603Four objects and two reference variables
3604Two objects and two reference variables.
36051
36060
36070
36080
3609Keywords_variables_operators_datatypes_NewQB
3610A) The purpose of the method overriding is to perform different operation, though input remains the same.B) one of the important Object Oriented principle is the code reusability that can be achieved using abstraction
3611MCQ
3612Only A is TRUE
3613Only B is True
3614Both A and B is True
3615Both A and B is FALSE
36161
36170
36180
36190
3620Keywords_variables_operators_datatypes_NewQB
3621class Test{ public static void main(String[] args){ byte b=(byte) (45 << 1); b+=4; System.out.println(b); }}What should be the output for the code written above?
3622MCQ
362348
362494
3625Compiles but error at run time
3626Compilation error
36270
36281
36290
36300
3631Keywords_variables_operators_datatypes_NewQB
3632What is the value of y when the code below is executed?int a = 4; int b = (int)Math.ceil(a % 3 + a / 3.0);
3633MCQ
36341
36352
36363
36374
36380
36390
36401
36410
3642Keywords_variables_operators_datatypes_NewQB
3643Consider the following code and choose the correct option:class Test{ class A{ interface X{ int z=4; } } static void display(){ System.out.println(new A().X.z); } public static void main(String[] args) { display(); }}
3644MCQ
3645Compilation error
3646Compiles but error at run time
36474
36480
36491
36500
36510
3652Keywords_variables_operators_datatypes_NewQB
3653Consider the code below & select the correct ouput from the options:public class Test { public static void main(String[] args) { String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ?elements[0] : null; System.out.println(first); }}
3654MCQ
3655Compilation error
3656The variable first is set to null.
3657The variable first is set to elements[0].
3658Compiles but error at runtime
36590
36600
36611
36620
3663Keywords_variables_operators_datatypes_NewQB
3664Given the following piece of code:public class Test {public static void main(String args[]) {int i = 0, j = 5 ;for( ; (i < 3) && (j++ < 10) ; i++ ) {System.out.print(" " + i + " " + j );}System.out.print(" " + i + " " + j );}}what will be the output?
3665MCQ
36660 6 1 7 2 8 3 8
36670 6 1 7 2 8 3 9
36680 5 1 5 2 5 3 5
3669compilation fails
36701
36710
36720
36730
3674Keywords_variables_operators_datatypes_NewQB
3675Given class MybitShift { public static void main(String [] args) { int a = 0x5000000; System.out.print(a + " and "); a = a >>> 25; System.out.println(a); }}
3676MCQ
367783886080 and -2
36782 and 83886080
36792 and -83886080
368083886080 and 2
36810
36820
36830
36841
3685Keywords_variables_operators_datatypes_NewQB
3686Consider the code below & select the correct ouput from the options:public class Test { int squares = 81; public static void main(String[] args) { new Test().go(); }void go() { incr(++squares); System.out.println(squares); } void incr(int squares) { squares += 10; } }
3687MCQ
368892
368991
3690Compilation error
369182
36920
36930
36940
36951
3696Keywords_variables_operators_datatypes_NewQB
3697class C{public static void main (String[] args) {byte b1=33; //1b1++; //2byte b2=55; //3b2=b1+1; //4System.out.println(b1+""+b2);}}Consider the code above & select the correct output.
3698MCQ
3699compile time error at line 2
3700compile time error at line 4
3701prints 34,56
3702runtime exception
3703none of the listed options
37040
37051
37060
37070
37080
3709Keywords_variables_operators_datatypes_NewQB
3710What will be the output of the program ? public class Test { public static void main(String [] args) { signed int x = 10; for (int y=0; y<5; y++, x--) System.out.print(x + ", "); }}
3711MCQ
371210, 9, 8, 7, 6,
37139, 8, 7, 6, 5,
3714Compilation fails
3715An exception is thrown at runtime
37160
37170
37181
37190
3720Keywords_variables_operators_datatypes_NewQB
37211. public class LineUp {2. public static void main(String[] args) {3. double d = 12.345;4. // insert code here5. }6. }Which code fragment, inserted at line 4, produces the output | 12.345|?A. System.out.printf("|%7f| \n", d);B. System.out.printf("|%3.7f| \n", d);C. System.out.printf("|%7.3d| \n", d);D. System.out.printf("|%7.3f| \n", d);
3722MCQ
3723A
3724B
3725C
3726D
37270
37280
37290
37301
3731Keywords_variables_operators_datatypes_NewQB
3732Consider the following code and choose the correct option:class Test{ interface Y{ void display(); } public static void main(String[] args) { Y y=new Y(){ public void display(){ System.out.println("Hello World"); } }; y.display(); }}
3733MCQ
3734Hello World
3735Compilation error
3736Compiles but error at run time
3737Compiles but run without output
37381
37390
37400
37410
3742Keywords_variables_operators_datatypes_NewQB
3743class Test{public static void main(String[] args){int var;var = var +1;System.out.println("var ="+var);}}consider the code above & select the proper output from the options.
3744MCQ
3745compiles and runs with no output
3746var = 1
3747does not compile
3748run time error
37490
37500
37511
37520
3753Keywords_variables_operators_datatypes_NewQB
3754State the class relationship that is being implemented by the following code:class Employee{private int empid;private String ename;public double getBonus(){Accounts acc = new Accounts();return acc.calculateBonus();}}class Accounts{public double calculateBonus(){//method's code}}
3755MCQ
3756Aggregation
3757Simple Association
3758Dependency
3759Composition
37600
37610
37621
37630
3764Keywords_variables_operators_datatypes_NewQB
3765Given classes A, B, and C, where B extends A, and C extends B, and where all classesimplement the instance method void doIt(). How can the doIt() method in A becalled from an instance method in C?
3766MCQ
3767It is not possible
3768super.doIt()
3769his.super.doIt()
3770((A) this).doIt();
3771A.this.doIt()
37721
37730
37740
37750
37760
3777Keywords_variables_operators_datatypes_NewQB
3778Which of the following will declare an array and initialize it with five numbers?
3779MCQ
3780Array a = new Array(5);
3781int [] a = {23,22,21,20,19};
3782int a [] = new int[5];
3783int [5] array;
37840
37851
37860
37870
3788Keywords_variables_operators_datatypes_NewQB
3789Which of the following are correct variable names? (Choose TWO)
3790MCA
3791int #ss;
3792int 1ah;
3793int _;
3794int $abc;
37950
37960
37970.5
37980.5
3799Keywords_variables_operators_datatypes_NewQB
3800What is the output of the following: int a = 0;int b = 10;a = --b ;System.out.println("a: " + a + " b: " + b );
3801MCQ
3802a: 9 b:11
3803a: 10 b: 9
3804a: 9 b:9
3805a: 0 b:9
38060
38070
38081
38090
3810Keywords_variables_operators_datatypes_NewQB
3811As per the following code fragment, what is the value of a?String s;int a;s = "Foolish boy.";a = s.indexOf("fool");
3812MCQ
3813-1
38144
3815random value
38161
38170
38180
38190
3820Keywords_variables_operators_datatypes_NewQB
3821Consider the following code snippet: int i = 10;int n = i++%5;What are the values of i and n after the code is executed?
3822MCQ
382310, 1
382411, 1
382510, 0
382611 , 0
38270
38280
38290
38301
3831Keywords_variables_operators_datatypes_NewQB
3832Consider the following code and choose the correct output:int value = 0;int count = 1;value = count++ ;System.out.println("value: "+ value + " count: " + count);
3833MCQ
3834value: 0 count: 0
3835value: 0 count: 1
3836value: 1 count: 1
3837value: 1 count: 2
38380
38390
38400
38411
3842Keywords_variables_operators_datatypes_NewQB
3843Consider the following code and select the correct output:class Test{ interface Y{ void display(); } public static void main(String[] args) { new Y(){ public void display(){ System.out.println("Hello World"); } }; }}
3844MCQ
3845Hello World
3846Compilation error
3847Compiles but error at run time
3848Compiles but run without output
38490
38500
38510
38521
3853Keywords_variables_operators_datatypes_NewQB
3854What is the output of the following program?public class demo { public static void main(String[] args) { int arr[5]; for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] + 10; } for (int j = 0; j < arr.length; j++) System.out.println(arr[j]); }}
3855MCQ
3856A sequence of five 10's are printed
3857A sequence of Garbage Values are printed
3858compile time Error
3859Compiles but no output
38600
38610
38621
38630
3864Threads_NewQB
3865Which of the following methods registers a thread in a thread scheduler?
3866MCQ
3867run();
3868construct();
3869start();
3870register();
38710
38720
38731
38740
3875Threads_NewQB
3876class PingPong2 {synchronized void hit(long n) {for(int i = 1; i < 3; i++)System.out.print(n + "-" + i + " ");}} public class Tester implements Runnable { static PingPong2 pp2 = new PingPong2(); public static void main(String[] args) { new Thread(new Tester()).start(); new Thread(new Tester()).start(); } public void run() { pp2.hit(Thread.currentThread().getId()); } }Which statement is true?
3877MCQ
3878The output could be 5-1 6-1 6-2 5-2
3879The output could be 6-1 6-2 5-1 5-2
3880The output could be 6-1 5-2 6-2 5-1
3881The output could be 6-1 6-2 5-1 7-1
38820
38831
38840
38850
3886Threads_NewQB
3887Consider the following code and choose the correct option:class Cthread extends Thread{ public void run(){ System.out.print("Hi");}public static void main (String args[]){ Cthread th1=new Cthread(); th1.run(); th1.start();th1.run();}}
3888MCQ
3889will print Hi twice and throws Exception at run time
3890will print Hi Thrice
3891Compilation error
3892will print Hi once
38930
38941
38950
38960
3897Threads_NewQB
3898class Cthread extends Thread{ public void run(){ System.out.print("Hi");}public static void main (String args[]){ Cthread th1=new Cthread(); th1.run(); th1.start(); th1.start();}}
3899MCQ
3900will start two thread
3901will print Hi Once
3902will not print
3903will print Hi twice and throws exception at runtime
39040
39050
39060
39071
3908Threads_NewQB
3909Consider the following code and choose the correct option:class Cthread extends Thread{ Cthread(){start();} public void run(){ System.out.print("Hi");}public static void main (String args[]){ Cthread th1=new Cthread();Cthread th2=new Cthread();}}
3910MCQ
3911will create two child threads and display Hi twice
3912compilation error
3913will not create any child thread
3914will display Hi once
39151
39160
39170
39180
3919Threads_NewQB
3920Which of the following methods are defined in class Thread? (Choose TWO)
3921MCA
3922start()
3923wait()
3924notify()
3925run()
3926terminate()
39270.5
39280
39290
39300.5
39310
3932Threads_NewQB
3933The following block of code creates a Thread using a Runnable target: Runnable target = new MyRunnable();Thread myThread = new Thread(target);Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
3934MCQ
3935public class MyRunnable implements Runnable{public void run(){}}
3936public class MyRunnable extends Runnable{public void run(){}}
3937public class MyRunnable implements Runnable{void run(){}}
3938public class MyRunnable extends Object{public void run(){}}
39391
39400
39410
39420
3943Threads_NewQB
3944Which of the following statements can be used to create a new Thread? (Choose TWO)
3945MCA
3946Extend java.lang.Thread and override the run() method.
3947Extend java.lang.Runnable and override the start() method.
3948Implement java.lang.Thread and implement the run() method.
3949Implement java.lang.Runnable and implement the run() method
3950Implement java.lang.Thread and implement the
39510.5
39520
39530
39540.5
39550
3956Threads_NewQB
3957What will be the output of the program? class MyThread extends Thread { MyThread() {} MyThread(Runnable r) {super(r); } public void run() { System.out.print("Inside Thread "); } } class MyRunnable implements Runnable { public void run() { System.out.print(" Inside Runnable"); } } class Test { public static void main(String[] args) { new MyThread().start(); new MyThread(new MyRunnable()).start(); } }
3958MCQ
3959Prints "Inside Thread Inside Thread"
3960Does not compile
3961Prints "Inside Thread Inside Runnable"
3962Throws exception at runtime
39631
39640
39650
39660
3967Threads_NewQB
3968A) Multiple processes share same memory locationB) Switching from one thread to another is easier than switching from one process to anotherC) Thread makes it possible to maximize resource utilizationD) Process is a light weight program
3969MCQ
3970All are FALSE
3971Only B and C is TRUE
3972Only A and B is TRUE
3973Only C and D is TRUE
39740
39751
39760
39770
3978Threads_NewQB
3979A) Exception is the superclass of all errors and exceptions in the java languageB) RuntimeException and its subclasses are unchecked exception.
3980MCQ
3981Only A is TRUE
3982Only B is TRUE
3983Both A and B are TRUE
3984Both A and B are FALSE
39850
39861
39870
39880
3989Threads_NewQB
3990What will be the output of the program? class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); t.start(); System.out.print("one. "); t.start(); System.out.print("two. "); } public void run() { System.out.print("Thread "); }}
3991MCQ
3992Compilation fails
3993An exception occurs at runtime.
3994It prints "Thread one. Thread two."
3995The output cannot be determined.
39960
39971
39980
39990
4000Threads_NewQB
4001Consider the following code and choose the correct option:class A implements Runnable{ int k;public void run(){k++; } public static void main(String args[]){A a1=new A();a1.run();}
4002MCQ
4003It will start a new thread
4004compilation error
4005Compiles but throws run time Exception
4006a1 is not a Thread
40070
40080
40090
40101
4011Threads_NewQB
4012Given: public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.print("run"); } }; Thread t = new Thread(r); t.start(); t.start(); } }What is the result?
4013MCQ
4014Compilation fails.
4015An exception is thrown at runtime.
4016The code executes normally and prints "run".
4017The code executes normally, but nothing is printed.
40180
40191
40200
40210
4022Threads_NewQB
4023class Thread2 { public static void main(String[] args) { new Thread2().go(); } public void go(){ Runnable rn=new Runnable(){ public void run(){ System.out.println("Good Day.."); } }; Thread t=new Thread(rn); t.start(); }}what should be the correct output for the code written above?
4024MCQ
4025Compilation fails.
4026An exception is thrown at runtime.
4027The code executes normally and prints "Good Day.."
4028prints Good Day.. Twice
40290
40300
40311
40320
4033Threads_NewQB
4034public class MyRunnable implements Runnable { public void run() { // some code here }}which of these will create and start this thread?
4035MCQ
4036new Runnable(MyRunnable).start();
4037new Thread(MyRunnable).run();
4038new MyRunnable().start();
4039new Thread(new MyRunnable()).start();
40400
40410
40420
40431
4044Threads_NewQB
4045Consider the following code and choose the correct option:class Nthread extends Thread{ public void run(){ System.out.print("Hi");} public static void main(String args[]){ Nthread th1=new Nthread(); Nthread th2=new Nthread();}
4046MCQ
4047Will create two child threads and display Hi twice
4048compilation error
4049will not create any child thread
4050will display Hi once
40510
40520
40531
40540
4055Threads_NewQB
4056Assume the following method is properly synchronized and called from a thread A on an object B:wait(2000);After calling this method, when will the thread A become a candidate to get another turn at the CPU?
4057MCQ
4058After thread A is notified, or after two seconds.
4059After the lock on B is released, or after two seconds.
4060Two seconds after thread A is notified.
4061Two seconds after lock B is released.
40621
40630
40640
40650
4066Threads_NewQB
4067wait(), notify() and notifyAll() methods belong to ________
4068MCQ
4069Object class
4070Thread class
4071Interrupt class
4072none of the listed options
40731
40740
40750
40760
4077strings_string_buffer_NewQB
4078Consider the following code and choose the correct option:class Test { public static void main(String[] args) { new Test().display("hi", 1); new Test().display("hi", "world", 2); } public void display(String... s, int x) { System.out.print(s[s.length-x] + " "); } }
4079MCQ
4080hi hi
4081hi world
4082world
4083Compilation error
40840
40850
40860
40871
4088strings_string_buffer_NewQB
4089Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String name="Anthony Gomes"; int a=111; System.out.println(name.indexOf(a)); }}
4090MCQ
40914
40922
40936
4094Compilation error
40951
40960
40970
40980
4099strings_string_buffer_NewQB
4100Given: String test = "This is a test"; String[] tokens = test.split("\s"); System.out.println(tokens.length);What is the result?
4101MCQ
41021
41034
4104Compilation fails.
41050
41060
41070
41081
4109strings_string_buffer_NewQB
4110Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String data="78"; System.out.println(data.append("abc")); }}
4111MCQ
411278abc
4113abc78
4114Compilation error
4115Compiles but exception at run time
41160
41170
41181
41190
4120strings_string_buffer_NewQB
4121Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String name="ALDPR7882E"; System.out.println(name.endsWith("E") & name.matches("[A-Z]{5}[0-9]{4}[A-Z]"));}}
4122MCQ
4123false
4124true
41251
41260
41271
41280
41290
4130strings_string_buffer_NewQB
4131Examine this code: String stringA = "Hello ";String stringB = " World";String stringC = " Java";String result;Which of the following puts a reference to "Hello World Java" in result?
4132MCQ
4133result = stringA.concat( stringB.concat( stringC ) );
4134result.concat( stringA, stringB, stringC );
4135result+stringA+stringB+stringC;
4136result = concat(StringA).concat(StringB).concat(StringC)
41371
41380
41390
41400
4141strings_string_buffer_NewQB
4142For two string objects obj1 and obj2:A) Use of obj1 == obj2 tests whether two String object references refer to the same objectB) obj1.equals(obj2) compares the sequence of characters in obj1 and obj2.
4143MCQ
4144Only A is TRUE
4145Only B is TRUE
4146Both A and B is TRUE
4147Both A and B is FALSE
41480
41490
41501
41510
4152strings_string_buffer_NewQB
4153What is the result of the following: String ring = "One ring to rule them all,\n";String find = "One ring to find them.";if ( ring.startsWith("One") && find.startsWith("One") ) System.out.println( ring+find );else System.out.println( "Different Starts" );
4154MCQ
4155One ring to rule them all, One ring to find them.
4156One ring to rule them all, One ring to find them.
4157One ring to rule them all,\n One ring to find them.
4158Different Starts
41591
41600
41610
41620
4163strings_string_buffer_NewQB
4164Consider the following code and choose the correct option:class MyClass {String str1="str1";String str2 ="str2";String str3="str3";str1.concat(str2);System.out.println(str3.concat(str1));}}
4165MCQ
4166The code will fail to compile because the expression str3.concat(str1) will not result in a valid argument for the println() method
4167The program will print str3str1str2,when run
4168The program will print str3,when run
4169The program will print str3str1,when run
4170The program will print str3str2,when run
41710
41720
41730
41741
41750
4176strings_string_buffer_NewQB
4177Given:public class Theory {public static void main(String[] args) {String s1 = "abc";String s2 = s1;s1 += "d";System.out.println(s1 + " " + s2 + " " + (s1==s2));StringBuffer sb1 = new StringBuffer("abc");StringBuffer sb2 = sb1;sb1.append("d");System.out.println(sb1 + " " + sb2 + " " + (sb1==sb2));}}Which are true? (Choose all that apply.)
4178MCA
4179Compilation fails
4180The first line of output is abc abc false
4181The first line of output is abcd abc false
4182The second line of output is abcd abc false
4183The second line of output is abcd abcd true
41840
41850
41860.5
41870
41880.5
4189strings_string_buffer_NewQB
4190class StringManipulation{public static void main(String[] args){String str = new String("Cognizant");str.concat(" Technology");StringBuffer sbf = new StringBuffer(" Solutions");System.out.println(str+sbf);}}consider the code above & select the proper output from the options.
4191MCQ
4192Cognizant Technology Solutions
4193Cognizant Technology
4194Cognizant Solutions
4195Technology Solutions
41960
41970
41981
41990
4200strings_string_buffer_NewQB
4201What does this code write: StringTokenizer stuff = new StringTokenizer( "abc def+ghi", "+");System.out.println( stuff.nextToken() );System.out.println( stuff.nextToken() );
4202MCQ
4203abc def
4204abc def ghi
4205abc def +
4206abc def +ghi
42070
42081
42090
42100
4211strings_string_buffer_NewQB
4212Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("antarctica"); sb.delete(0,6); System.out.println(sb); }}
4213MCQ
4214tica
4215anta
4216Compilation error
4217Complies but exception at run time
42181
42190
42200
42210
4222strings_string_buffer_NewQB
4223Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String name="vikaramaditya"; System.out.println(name.substring(2, 5).toUpperCase().charAt(2));}}
4224MCQ
4225K
4226A
4227R
4228I
42290
42300
42311
42320
4233strings_string_buffer_NewQB
4234Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("antarctica"); sb.reverse(); sb.replace(2, 7, "c"); sb.delete(0,2); System.out.println(sb); }}
4235MCQ
4236acctna
4237iccratna
4238ctna
4239tna
42400
42410
42421
42430
4244strings_string_buffer_NewQB
4245Consider the following code and choose the correct option:class Test { public static void main(String args[]) { String s1 = "abc"; String s2 = "def"; String s3 = s1.concat(s2.toUpperCase( ) ); System.out.println(s1+s2+s3); } }
4246MCQ
4247abcdefabcdef
4248abcabcDEFDEF
4249abcdefabcDEF
4250none of the listed options
42510
42520
42531
42540
4255strings_string_buffer_NewQB
4256What will be the result when you attempt to compile and run the following code?. public class Conv { public static void main(String argv[]){ Conv c=new Conv(); String s=new String("ello"); c.amethod(s); } public void amethod(String s){ char c='H'; c+=s; System.out.println(c); }}
4257MCQ
4258Compilation and output the string "Hello"
4259Compilation and output the string "ello"
4260Compilation and output the string elloH
4261Compile time error
42620
42630
42640
42651
4266strings_string_buffer_NewQB
4267Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String name="Anthony Gomes"; System.out.println(name.replace('n', name.charAt(3)).compareTo(name)); }}
4268MCQ
4269-6
42706
4271Compilation error
42721
42730
42740
42750
4276strings_string_buffer_NewQB
4277Consider the following code and choose the correct option:class Test { public static void main(String args[]) { String name=new String("batman"); int ibegin=1; char iend=3; System.out.println(name.substring(ibegin, iend)); } }
4278MCQ
4279bat
4280at
4281atm
4282Compilation error
42830
42841
42850
42860
4287strings_string_buffer_NewQB
4288Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { StringBuffer sb=new StringBuffer("YamunaRiver"); System.out.println(sb.capacity()); }}
4289MCQ
429010
429127
429224
429311
42940
42951
42960
42970
4298strings_string_buffer_NewQB
4299Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("antarctica"); sb.reverse(); sb.insert(4, 'r'); sb.replace(2, 4, "c"); System.out.println(sb); }}
4300MCQ
4301acitcratna
4302acitrcratna
4303accircratna
4304accrcratna
43050
43060
43070
43081
4309strings_string_buffer_NewQB
4310A)A string buffer is a mutable sequence of characters.B) sequece of characters in the string buffer can not be changed.
4311MCQ
4312Only A is TRUE
4313Only B is TRUE
4314Both A and B is TRUE
4315Both A and B is FALSE
43161
43170
43180
43190
4320strings_string_buffer_NewQB
4321Examine this code: String stringA = "Wild";String stringB = " Irish";String stringC = " Rose";String result;Which of the following puts a reference to "Wild Irish Rose" in result?
4322MCQ
4323result = stringA.concat( stringB.concat( stringC ) );
4324result.concat( stringA, stringB, stringC );
4325result+stringA+stringB+stringC;
4326result = concat(StringA).concat(StringB).concat(StringC)
43271
43280
43290
43300
4331strings_string_buffer_NewQB
4332Consider the following code and choose the correct option:class Test { public static void main(String[] args) { new Test().display(1,"hi"); new Test().display(2,"hi", "world" ); } public void display(int x,String... s) { System.out.print(s[s.length-x] + " "); }}
4333MCQ
4334hi hi
4335hi world
4336world
4337Compilation error
43381
43390
43400
43410
4342strings_string_buffer_NewQB
4343Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String name="vikaramaditya"; System.out.println(name.codePointAt(2)+name.charAt(3)); }}
4344MCQ
4345203
4346204
4347205
4348Compilation error
43490
43501
43510
43520
4353strings_string_buffer_NewQB
4354Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { String data="7882"; data+=32; System.out.println(data); }}
4355MCQ
43567914
4357Compiles but exception at run time
4358788232
4359Compilation error
43600
43610
43621
43630
4364strings_string_buffer_NewQB
4365Which code can be inserted at Line X to print "Equal"?public class EqTest{ public static void main(String argv[]){ EqTest e=new EqTest(); } EqTest(){ String s="Java"; String s2="java"; // Line X { System.out.println("Equal"); }else { System.out.println("Not equal"); } }}
4366MCQ
4367if(s==s2)
4368if(s.equals(s2))
4369if(s.equalsIgnoreCase(s2))
4370if(s.noCaseMatch(s2))
4371if(s.equalIgnoreCase(s2))
43720
43730
43741
43750
43760
4377IO_Operations_NewQB
4378import java.io.*;public class MyClass implements Serializable {private int a;public int getA() { return a; }publicMyClass(int a){this.a=a; }private void writeObject( ObjectOutputStream s)throws IOException {// insert code here}}Which code fragment, inserted at line 15, will allow Foo objects to becorrectly serialized and deserialized?
4379MCQ
4380s.writeInt(x);
4381s.serialize(x);
4382s.defaultWriteObject();
4383s.writeObject(x);
43840
43850
43861
43870
4388IO_Operations_NewQB
4389Which of the following opens the file "myData.stuff" for output first deleting any file with that name?
4390MCQ
4391FileOutputStream fos = new FileOutputStream( "myData.stuff", true )
4392FileOutputStream fos = new FileOutputStream( "myData.stuff")
4393DataOutputStream dos = new DataOutputStream( "myData.stuff" )
4394FileOutputStream fos = new FileOutputStream( new BufferedOutputStream( "myData.stuff") )
43950
43961
43970
43980
4399IO_Operations_NewQB
4400import java.io.*;public class MyClass implements Serializable {private Tree tree = new Tree();public static void main(String [] args) {MyClass mc= new MyClass();try {FileOutputStream fs = new FileOutputStream(â€MyClass.serâ€);ObjectOutputStream os = new ObjectOutputStream(fs);os.writeObject(mc); os.close();} catch (Exception ex) { ex.printStackTrace(); }} }
4401MCQ
4402Compilation fails
4403An exception is thrown at runtime
4404An instance of MyClass is serialized
4405A instance of MyClass and an instance of Tree are both serialized
44061
44070
44080
44090
4410IO_Operations_NewQB
4411Consider the following code and choose the correct option:class std implements Serializable{ int call; std(int c){call=c;} int getCall(){return call;}}public class Test{ public static void main(String[] args) throws IOException { File file=new File("d:/std.txt"); FileOutputStream fos=new FileOutputStream(file); ObjectOutputStream oos=new ObjectOutputStream(fos); std s1=new std(10); oos.writeObject(s1); oos.close(); }}
4412MCQ
4413the state of the object s1 will be store to file std.txt
4414Compilation error
4415Compiles but error at run time
4416the state of the object s1 will not be store to the file.
44171
44180
44190
44200
4421IO_Operations_NewQB
4422Consider the following code and choose the correct option:public class Test { public static void main(String[] args) throws IOException { File file=new File("D:/jlist.lst"); byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream(file); int ch=0; while((ch=fis.read())!=-1){ System.out.print(ch); } }}
4423MCQ
4424reads data from file one byte at a time and display it on the console.
4425Compilation error
4426reads data from file named jlist.lst in byte form and ascii value
4427Compiles but error at runtime
44280
44290
44301
44310
4432IO_Operations_NewQB
4433Consider the following code and choose the correct option:public class Test { public static void main(String[] args) throws IOException { File file=new File("D:/jlist.lst"); byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream(file); int ch=0; while((ch=fis.read())!=-1){ System.out.print((char)ch); } }}
4434MCQ
4435reads data from file one byte at a time and display it on the console.
4436Compilation error
4437reads data from file named jlist.lst in byte form and display garbage value
4438Compiles but error at runtime
44391
44400
44410
44420
4443IO_Operations_NewQB
4444Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { File file=new File("d:/prj/lib"); file.mkdirs();}}
4445MCQ
4446creates directory d:/prj/lib
4447Compilation error
4448Compiles but error at run time
4449Compiles and executes but directory is not created
44501
44510
44520
44530
4454IO_Operations_NewQB
4455Consider the following code and choose the correct option:public class Test { public static void main(String[] args) throws IOException { String data="Confidential info"; byte buffer[]=data.getBytes(); FileOutputStream fos=new FileOutputStream("d:/temp"); for(byte d : buffer){ fos.write(d); } }}
4456MCQ
4457writes data to file in byte form.
4458Compilation error
4459writes data to the file in character form.
4460Compiles but error at runtime
44611
44620
44630
44640
4465IO_Operations_NewQB
4466Given : import java.io.*; public class ReadingFor { public static void main(String[] args) { String s; try { FileReader fr = new FileReader("myfile.txt"); BufferedReader br = new BufferedReader(fr); while((s = br.readLine()) != null) System.out.println(s); br.flush(); } catch (IOException e) { System.out.println("io error"); } }}And given that myfile.txt contains the following two lines of data:abcdWhat is the result?
4467MCQ
4468ab
4469abcd
4470ab cd
4471a b c d
4472Compilation Error
44730
44740
44750
44760
44771
4478IO_Operations_NewQB
4479Consider the following code and choose the correct option:class std{ int call; std(int c){call=c;} int getCall(){return call;}}public class Test{ public static void main(String[] args) throws IOException { File file=new File("d:/std.txt"); FileOutputStream fos=new FileOutputStream(file); ObjectOutputStream oos=new ObjectOutputStream(fos); std s1=new std(10); oos.writeObject(s1); oos.close(); }}
4480MCQ
4481the state of the object s1 will be store to file std.txt
4482Compilation error
4483Compiles but error at run time
4484the state of the object s1 will not be store to the file.
44850
44860
44871
44880
4489IO_Operations_NewQB
4490Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { File file=new File("D:/jlist.lst"); byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream(file); fis.read(buffer); System.out.println(buffer); }}
4491MCQ
4492reads data from file named jlist.lst in byte form and display it on console.
4493Compilation error
4494reads data from file named jlist.lst in byte form and display garbage value
4495Compiles but error at runtime
44960
44971
44980
44990
4500IO_Operations_NewQB
4501Consider the following code and choose the correct option:public class Test { public static void main(String[] args) throws IOException { File file=new File("D:/jlist.lst"); byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream(file); fis.read(buffer); System.out.println(new String(buffer)); }}
4502MCQ
4503reads data from file named jlist.lst in byte form and display it on console.
4504Compilation error
4505reads data from file named jlist.lst in byte form and display garbage value
4506Compiles but error at runtime
45071
45080
45090
45100
4511IO_Operations_NewQB
4512What happens when the constructor for FileInputStream fails to open a file for reading?
4513MCQ
4514throws a DataFormatException
4515throws a FileNotFoundException
4516throws a ArrayIndexOutOfBoundsException
4517returns null
45180
45191
45200
45210
4522IO_Operations_NewQB
4523Consider the following code and choose the correct option:public class Test { public static void main(String[] args) { File file=new File("d:/prj,d:/lib"); file.mkdirs();}}
4524MCQ
4525creates directories names prj and lib in d: drive
4526Compilation error
4527Compiles but error at run time
4528Compiles and executes but directories are not created
45290
45300
45310
45321
4533IO_Operations_NewQB
4534Consider the following code and choose the correct output:public class Person{public void talk(){ System.out.print("I am a Person "); }}public class Student extends Person {public void talk(){ System.out.print("I am a Student "); }}what is the result of this piece of code:public class Test{public static void main(String args[]){Person p = new Student();p.talk();}}
4535MCQ
4536I am a Person
4537I am a Student
4538I am a Person I am a Student
4539I am a Student I am a Person
45400
45411
45420
45430
4544IO_Operations_NewQB
4545Which of these are two legal ways of accessing a File named "file.tst" for reading. Select the correct option:A)FileReader fr = new FileReader("file.tst"); B)FileInputStream fr = new FileInputStream("file.tst");C)InputStreamReader isr = new InputStreamReader(fr, "UTF8"); D)FileReader fr = new FileReader("file.tst", "UTF8");
4546MCQ
4547A,D
4548B,C
4549C,D
4550A,B
45510
45520
45530
45541
4555IO_Operations_NewQB
4556What is the DataOutputStream method that writes double precision floating point values to a stream?
4557MCQ
4558writeBytes()
4559writeFloat()
4560write()
4561writeDouble()
45620
45630
45640
45651
4566IO_Operations_NewQB
4567Consider the following code and choose the correct option:public class Test{ public static void main(String[] args) { File dir = new File("dir"); dir.mkdir(); File f1 = new File(dir, "f1.txt"); try { f1.createNewFile(); } catch (IOException e) { ; } File newDir = new File("newDir"); dir.renameTo(newDir);} }
4568MCQ
4569The file system has a new empty directory named dir
4570The file system has a new empty directory named newDir
4571The file system has a directory named dir, containing a file f1.txt
4572The file system has a directory named newDir, containing a file f1.txt
4573Compilation error
45740
45750
45760
45771
45780
4579IO_Operations_NewQB
4580Consider the following code and choose the correct option:public class Test { public static void main(String[] args) throws IOException { File file=new File("d:/data"); byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream(file); fis.read(buffer); FileWriter fw=new FileWriter("d:/temp.txt"); fw.write(new String(buffer));}}
4581MCQ
4582Transfer content of file data to the temp.txt
4583Compilation error
4584Compiles but error at runtime
4585Compiles and runs but content not transferred to the temp.txt
45860
45870
45880
45891
4590IO_Operations_NewQB
4591import java.io.EOFException;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;public class MoreEndings {public static void main(String[] args) {try {FileInputStream fis = new FileInputStream("seq.txt");InputStreamReader isr = new InputStreamReader(fis);int i = isr.read();while (i != -1) {System.out.print((char)i + "|");i = isr.read();}} catch (FileNotFoundException fnf) {System.out.println("File not found");} catch (EOFException eofe) {System.out.println("End of stream");} catch (IOException ioe) {System.out.println("Input error");}}}Assume that the file "seq.txt" exists in the current directory, has the requiredaccess permissions, and contains the string "Hello".Which statement about the program is true?
4592MCQ
4593The program will not compile because a certain unchecked exception is not caught.
4594The program will compile and print H|e|l|l|o|Input error.
4595The program will compile and print H|e|l|l|o|End of stream.
4596The program will compile, print H|e|l|l|o|, and then terminate normally.
45970
45980
45990
46001
4601IO_Operations_NewQB
4602Consider the following code and choose the correct option:public class Test{ public static void main(String[] args) throws IOException { File file = new File("d:/temp.txt"); FileReader reader=new FileReader(file); reader.skip(7); int ch; while((ch=reader.read())!=-1){ System.out.print((char)ch); } }}
4603MCQ
4604Skip the first seven characters and then starts reading file and display it on console
4605Compilation error
4606Compiles and runs without output
4607Compiles but error at runtime
46081
46090
46100
46110
4612IO_Operations_NewQB
4613A file is readable but not writable on the file system of the host platform. What willbe the result of calling the method canWrite() on a File object representing this file?
4614MCQ
4615A SecurityException is thrown
4616The boolean value false is returned
4617The boolean value true is returned
4618The file is modified from being unwritable to being writable.
4619none of the listed options
46200
46211
46220
46230
46240
4625Introduction_to_OOPS_NewQB
4626Which of following set of functions are example of method overloading
4627MCQ
4628void add(int x,int y) char add(int x,int y)
4629char add(float x) char add(float y)
4630void add(int x,int y) char add(char x,char y)
4631void add(int x,int y) void sum(double x,double y)
46320
46330
46341
46350
4636Introduction_to_OOPS_NewQB
4637What is the advantage of runtime polymorphism?
4638MCQ
4639Efficient utilization of memory at runtime
4640Code reuse
4641Code flexibility at runtime
4642avoiding method name confusion at runtime
46430
46440
46451
46460
4647Introduction_to_OOPS_NewQB
4648Which of the following is an example of IS A relationship?
4649MCQ
4650Ford - Car
4651Microprocessor - Computer
4652Tea -Cup
4653Driver -Car
46541
46550
46560
46570
4658Introduction_to_OOPS_NewQB
4659Which of the following is not a valid relation between classes?
4660MCQ
4661Inheritance
4662Segmentation
4663Instantiation
4664Composition
46650
46661
46670
46680
4669Introduction_to_OOPS_NewQB
4670Which of the following is not an attribute of object?
4671MCQ
4672State
4673Behaviour
4674Inheritance
4675Identity
46760
46770
46780
46791