-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFull Quiz Test Questions.txt
2052 lines (1535 loc) · 39.9 KB
/
Full Quiz Test Questions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
,What is the size of a double variable in Java?
,A. 2 Bytes
,B. 4 Bytes
,C. 8 Bytes
,D. It depends on the compiler setting
,E. It depends on the opertating System
,C
,1
,What is the output from the following code?
int x = 5 and y = 2;
System.out.println(x/y - (double)(x/y));
,A. 0
,B. 0.5
,C. -0.5
,D. -2.5
,E. None of the above
,A
,3
,What is displayed by:
System.out.println("1" + new Integer(2) + 3);
,A. The statement has a syntax error and wont't compile
,B. 6
,C. 15
,D. 123
,E. ClassCastException
,D
,3
,Consider the method:
public String mystery(String s)
{
String s1 = s.substring(0);
String s2 = s.substring(1);
String s3 = s.substring(2);
if (s.length() <= 3)
return s3 + s2 + s1;
else
return s1 + mystery(s2) + s3;
}
What is the output of
System.out.println(mystery("DELIVER"));
,A. DELIVER
,B. DEVILER
,C. REVILED
,D. RELIVED
,E. DELIVERELIVERLIVERIVERRERVERERVERIVERLIVER
,E
,5
,What is the output by the code below?
System.out.print("ab\\ab" );
What is the output of the following code segment above?
,A. abab
,B. ab
,C. ab\ab
,D. bab
,E. aba
,C
,3
,Suppose an array A has n elements. Let's call it periodic with a period of p if 0 < p < n and A[i] == A[i+p] for all 0 <= i < n-p and p is the smallest such number.
What is the period of array v after the following code is executed?
int v[] = new int[100];
v[0] = 0; v[1] = 1;
for (int i = 2; i < 100; i++)
v[i] = v[i-1] - v[i-2];
What would the output be by executing the getTotal(); ?
,A. 7
,B. 6
,C. 4
,D. 45
,E. Integer.MAX_VALUE
,B
,5
,Consider the following two classes:
public class Dog
{
public void act()
{
System.out.print("run ");
eat();
}
public void eat()
{
System.out.print("eat ");
}
}
public class UnderDog extends Dog
{
public void act()
{
super.act();
System.out.print("sleep ");
}
public void eat()
{
super.eat();
System.out.print("bark ");
}
}
Assume that the following declaration appears in a class other than Dog.
Dog fido = new UnderDog();
What is printed as a result of the call fido.act() ?
,A. run eat
,B. run eat sleep
,C. run eat sleep bark
,D. run eat bark sleep
,E. None of the above.
,D
,7
,What is the output of the following code?
int sum = 0
int p = 1;
for (int count = 1; count <= 50; count++)
{
sum += p;
p *= 2;
}
,A. -1
,B. 562949953421311
,C. 1125899906842623
,D. infinity due to infinte loop
,E. null
,A
,8
,A recursive method upNdown is defined as follows:
public void upNdown(int n)
{
if (n > 1)
{
if (n % 2 != 0) upNdown(n+1);
else upNdown(n/2);
System.out.println("*");
}
}
How many stars are displayed when upNdown(5) is called?
,A. 1
,B. 2
,C. 3
,D. 4
,E. 5
,E
,8
,The method mixup is defined as follows:
String mixup(String word)
{
if (word.length() == 1)
return "";
else
return mixup(word.substring(0)) + word.charAt(word.length() - 1);
}
What is the value of the string returned by mixup("IDEAL")?
,A. IDEAL
,B. DEAL
,C. LEAD
,D. DEAI
,E. Syntax error
,E
,9
,Consider the following program:
import myLibrary.*;
public class ShowSomeClass
{
// code for the class...
}
What is the name of the java file containing this program?
,A.myLibrary.java
,B.ShowSomeClass.java
,C.ShowSomeClass
,D.ShowSomeClass.class
,E.Any file name with the java suffix will do
,B
,2
,Which of the following is TRUE?
,A.In java; an instance field declared publicgenerates a compilation error.
,B.int is the name of a class available in the package java.lang
,C.Instance variable names may only contain letters and digits.
,D.A class has always a constructor (possibly automatically supplied by the java compiler).
,E.The more comments in a program; the faster the program runs.
,D
,2
,Consider the following code snippet
String river = new String(“Columbia”);
System.out.println(river.length());
What is printed?
,A.6
,B.7
,C.8
,D.Columbia
,E.river
,C
,1
,A constructor
,A. must have the same name as the class it is declared within.
,B. is used to create objects.
,C. may be declared private
,D. A and B
,E. A B and C
,E
,3
,Which of the following may be part of a class definition?
,A. instance variables
,B. instance methods
,C. constructors
,D. all of the above
,E. none of the above
,D
,3
,What is different between a Java applet and a Java application?
,A. An application can in general be trusted whereas an applet can't
,B. An applet must be executed in a browser environment
,C. An applet is not able to access the files of the computer it runs on
,D. (A) (B) and (C).
,E. None of the above
,D
,5
,Consider
public class MyClass{
public MyClass(){/*code*/}
// more code...
}
To instantiate MyClass; you would write?
,A. MyClass mc = new MyClass();
,B. MyClass mc = MyClass();
,C. MyClass mc = MyClass;
,D. MyClass mc = new MyClass;
,E. It can't be done. The constructor of MyClass should be defined as public void MyClass(){/*code*/}
,A
,2
,What is byte code in the context of Java?
,A. The type of code generated by a Java compiler
,B. The type of code generated by a Java Virtual Machine
,C. It is another name for a Java source file
,D. It is the code written within the instance methods of a class.
,E. It is another name for comments written within a program.
,A
,1
,What is garbage collection in the context of Java?
,A.The operating system periodically deletes all of the java files available on the system.
,B. Any package imported in a program and not used is automatically deleted.
,C. When all references to an object are gone; the memory used by the object is automatically reclaimed.
,D.The JVM checks the output of any Java program and deletes anything that doesn't make sense.
,E. Janitors working for Sun MicroSystems are required to throw away any Microsoft documentation found in the employees' offices.
,C
,4
,You read the following statement in a Java program that compiles and executes.
submarine.dive(depth);
What can you say for sure?
,A. depth must be an int
,B. dive must be a method.
,C. dive must be the name of an instance field.
,D. submarine must be the name of a class
,E. submarine must be a method.
,B
,5
,Consider
int a = 6;
int b = 12;
while(a<b){
System.out.println("In the loop");
a+=2;
b-=2;
}
How many times is the phrase "In the loop" printed?
,A.1
,B.2
,C.3
,D.4
,E.5
,B
,1
,In Java; elements of an array are automatically initialized to some default value.
What is the default value for the elements of an array of integers?
,A.0
,B."0"
,C.null
,D.1
,E.'0'
,A
,2
,You want to initialize all of the elements of a double array a to the same value equal to 1.5.What could you write?
Assume that the array has been correctly initialized.
,A. for(int i=1; i<a.length; i++) a[i] = 1.5;
,B. for(int i=0; i<=a.length; i++) a[i] = 1.5;
,C.for(int i=0; i<a.length; i++) a[i] = 1.5;
,D.for(int i=0; i<a.length+1; i++) a[i] = 1.5;
,E.for(int i=0; i<a.length-1; i++) a[i] = 1.5;
,C
,5
,Which of the following while statements is equivalent to
do{
y=x+7;
x++;
}while(x<9);
(Hint: You might want to draw a flow chart to figure out the answer)
,A.
y=x+7;
x++;
while(x<9){
y=x+7;
x++;
}
,B.
while(x<9){
y=x+7;
x++;
}
y=x+7;
x++;
,C.
while(x<=9){
y=x+7;
x++;
}
,D.A and B
,E.A B and C
,A
,6
,Consider the code
int[] x = {5 6 7 8 9};//Assume actual code has commas separating input instead of spaces
int[] y = x;
y[2] = 10;
What is the value of x[2]?
,A.6
,B.7
,C.10
,D.8
,E.0
,C
,6
,Consider the following piece of code:
int i;
for(i=0; i<10; i++){
/* some code that doesn't modify i */
}
System.out.println("i="+i); /* line A */
What is printed by the statement on line A?
,A.i=0
,B.i=9
,C.i=10
,D.i=11
,E.This piece of code doesn't compile since the scope of i is limited to the for loop.
,C
,6
,What is printed by the following code fragment?
int[] a = {0 1 2 3 4 5 6};//Assume actual code has commas separating input instead of spaces
System.out.println(a.length);
,A.5
,B.6
,C.7
,D.8
,E.Can't tell. There is not enough information.
,C
,5
,How would you declare and initialize a palette of Color objects Array of size 6?
,A. Color palette = new Color[5];
,B. Color palette[6];
,C. Color[5] palette;
,D. Color[] palette = new Color[6];
,E. Color[] palette = new Color[5];
,D
,5
,The documentation of a class lists a method castToIntArray that has a double array as a formal
parameter and returns an array of integers. What is the signature of the method?
,A. public void castToIntArray(double[] a)
,B. public [] castToIntArray(double a)
,C. public int castToIntArray(double a)
,D. public int[] castToIntArray(double[] a)
,E. public int[] castToIntArray()
,D
,6
,Which of the following is true regarding the continue statement in a for loop?
,A. continue transfers the control flow to the initialization statement of the for loop.
,B. continue transfers the control flow to the conditional statement of the for loop.
,C. continue transfers the control flow to the update statement of the for loop.
,D. continue transfers the control flow to the statement just after the for loop
,E. continue transfers the control flow to the statement just before the for loop
,C
,8
,Which of these is an actual Exception that is able to be thrown?
,A. AssetMissingException
,B. MissingPacketException
,C. FileNotFoundException
,D. CompileException
,E. NullRedistException
,C
,4
,Which of these service classes are used to read files?
,A. FileReader
,B. ArrayList
,C. Scanner
,D. BufferedReader
,E. A and D
,E
,4
,What is the main return type of the main method?
,A. String[]
,B. ArrayList<String[]>
,C. void
,D. args
,E. A and C
,C
,3
,Is it possible to make an ArrayList of ArrayLists?
,A. No - ArrayLists cannot hold ADTs (Abstract Data Types)
,B. Yes
,C. No - however you can make an ArrayList of primitive arrays
,D. Only if the ArrayList contained within the other contains a primitive data type
,E. No - ArrayLists can only store primitive data types (e.g. int or double)
,B
,2
,What does this loop print?
for(int i = 0;i <= 5;i++)
{
System.out.println("[" + i + "]");
}
,A. 5 Boxes with the letter "i" inside on the same line
,B. 6 boxes with the letter "i" inside on seperate lines
,C. 4 boxes with the numbers 0 through 4 on seperate lines
,D. 6 boxes with the numbers 0 through 5 on seperate lines
,E. 5 boxes with the number 0 inside on seperate lines
,D
,3
,What are different types of access modifiers in Java?
,A. Private Protected Default and Public
,B. Protected Default and Public
,C. Private Protected and Public
,D. Private Protected and Default
,E. Restricted Private and Public
,C
,5
,Which of these is not a Java IDE?
,A.Netbeans
,B.Eclipse
,C.DrJava
,D.Espresso
,E.JDeveloper
,D
,3
,What is an interface?
,A.A collection of abstract methods
,B.A system of graphic images
,C.A visual element that is able to be imported from the service class java.util.Interface
,D.A bunch of empty fields that you can enter values in
,E.A lousy outdated way of thinking
,A
,6
,What does CSV stand for?
,A.Conditional Serial Verification
,B.Comma Seperated Values
,C.Critical System Virus
,D.Constant Stack Vent
,E.Clear Source Values
,B
,3
,Which of these is a Java keyword?
,A.remove
,B.base
,C.direct
,D.root
,E.finally
,E
,4
,Which of the following is the decimal value for the following binary number?
1001011
,A.74
,B.75
,C.67
,D.150
,E.43
,B
,1
,What is the value of n after the following code is executed?
int n = 2005;
for (int i = 0; i < 50; i++)
{
n = (n + 3) / 2;
}
,A.0
,B.1
,C.2
,D.3
,E.65
,D
,2
,Consider the following classes.
public abstract class Animal
{
public void run()
{
System.out.println("Running");
}
}
public class Cheetah extends Animal
{
public void run()
{
System.out.println("Running really fast");
}
}
What will be printed out when the below code segment is run?
Animal c = new Cheetah();
c.run();
,A.Running really fast
,B.Running
,C.Nothing will be printed. There will be a runtime error
,D.Running really fast
Running
,E.Running
Running really fast
,A
,3
,What is encapsulation and how does Java implement it?
,A.Encapsulation: data (fields) can be directly accessed by code in all classes. Java implements encapsulation using the visibility modifier public.
,B.Encapsulation: data (fields) can be hidden inside of an object and this can be accomplished in Java by using the abstract visibility modifier.
,C.Encapsulation: data (fields) can be hidden inside an object so that they cannot be directly altered by code in other classes. Java implements encapsulation using the visibility modifier private.
,D.Encapsulation: data (fields) are directly accessible by objects in the same package.
,E.Encapsulation: data (fields) are directly accessible by objects in the same package and in subclasses.
,C
,3
,public class Student {
public String getFood() {
return "Pizza";
}
public String getInfo() {
return this.getFood();
}
}
public class GradStudent extends Student {
public String getFood() {
return "Taco";
}
}
What is the output from this:
Student s1 = new GradStudent();
s1.getInfo();
,A.Won't compile since you are creating a GradStudent not a Student
,B.Pizza
,C.Won't compile since you use this.getFood()
,D.Taco
,E.Won't compile since GradStudent doesn?t have a getInfo method
,D
,5
,The following method attempts to perform an insertion sort:
public void sort()
0: {
1: for (int i = 1; i < a.length; i++)
2: {
3: int next = a[i];
4: // Move all larger elements to the right
5: int j = i;
6: while (j > 0 && a[j - 1] > next)
7: {
8: a[j-1] = a[j];
9: j--;
10: }
11: // Insert the element
12: a[j] = next;
13: }
14: }
However it does not work properly. Which is the line that contains an error?
,A. In line 1 the code i < a.length should be i < a.length ? 1.
,B. In line 5 should be int j = i + 1;
,C. In line 6 the code j > 0 should be j < i.
,D. In line 8 it should be a[j] = a[j-1];
,E. In line 1 the code should be for (int i = 0; i < a.length; i++)
,D
,5
,If a is and int array of length 2 and a[0] and a[1] holds values 7 and 13 respectively. What are their values after fun(a) is called? The method fun is defined as follows:
public void fun(int[] x)
{
x[0] = (int)(100.0 * x[0] / (x[0] + x[1]));
x[1] = (int)(100.0 * x[1] / (x[0] + x[1]));
}
,A.7 and 13
,B.35 and 27
,C.34 and 64
,D.35 and 65
,E.34 and 66
,B
,3
,Which of the following best describes the purpose of a method's pre and post conditions?
,A.They permit the method to be in a different file than the code which calls the method
,B.They initialize necessary variables so the method will run correctly.
,C.They explain how a method was implemented
,D.They communicate with the compiler
,E.They provide information to the programmer or reader about what the method is intended to do.
,E
,4
,What is the difference between an interface and an abstract class?
,A.An abstract class is a class that may or may not have abstract methods. Abstract classes cannot be instantiated
and the cannot be sub-classed. An interface is a reference type. Similar to a class that can contain only constants
and/or method signatures. There are no method bodies. Interfaces cannot be instantiated. They can only be implemented
by classes or extended by other interfaces.
,B.An abstract class is a class that is declared abstract. it may or may not include abstract methods. Abstract
classes cannot be instantiated. But they can be sub-classed. The subclass usually provides implementations for all of
the abstract methods in its parent class. However if it does not; the subclass must also be declared abstract. An
interface is a special kind of abstract class that can contain only class constants and method signatures. There are
no method bodies allowed in methods in an interface. Interfaces cannot be instantiated. They can only be implemented
by classes or extended by other interfaces.
,C.An abstract class is a class that is declared abstract. Abstract classes can be instantiated. But they cannot be
sub-classed. An interface is a class that can contain only method bodies. Interfaces can be instantiated. But they
cannot be implemented by classes or extended by other interfaces.
,D.There are no differences between an abstract class and an interface. They are both classes that can have abstract
and non-abstract methods and there are no method bodies. Neither of them can be instantiated. But they can be
sub-classed.
,E.An abstract class is a class that is declared abstract. It may or may not include abstract methods. Abstract classes
cannot be instantiated. But they can be sub-classed. The subclass usually provides implementations for all of the
abstract methods in its parent class. However if it does not; the subclass must also be declared abstract. An
interface is is class that has method bodies.
,B
,7
,What is the output of the following code?
int a = 1;
int b = 2;
int c = 3;
a += b + c;
b += a + c;
c += a + b;
System.out.println(a + " " + b + " " + c);
,A.3 3 4
,B.3 5 6
,C.5 4 3
,D.5 8 13
,E.6 11 20
,E
,2
,What does IPO stand for in computer science?
,A. Indiana Planetary Observatory
,B. Initial Public Offering
,C. Input Processing Output
,D. International Pacific Ocean
,E. Indexed Program Object
,c
,2
,Which is not a basic concept of Object-Oriented Programming?
,A. Encapsulation
,B. Inheritance
,C. Polymorphism
,D. Extraction
,
E. Abstraction
,d
,4
,What is operator overloading?
,A. Where operators are called in till a stack-overflow error
,B. Where different operators have different implementations depending on their arguments
,C. Where a sub class implements the same method as its super class
,D. When an error occurs due to identical methods in the sub and super classes
,E. Timing out the JVM
,b
,7
,According to the Java API: Real-world objects contain _____ and _____. A software object's state is stored in _____.
,A. state. behaviour. fields.
,B. methods. code. variables.
,C. functions. processes. random-access-memory.
,D. behaviour. attributes. data-cells.
,E. Source Code. Byte Code. The JVM.
,a
,9
,What does the term API stands for?
,A. Attribute Processing Implementation
,B. Application Parameter Index
,C. Application Programming Interface
,D. Assisted Processing Index
,E. Applet Parameter Implementation
,c
,8
,How can you prevent your class to be inherited further?
,A. Ask nicely in the JavaDoc
,B. Use the "closed" keyword
,C. Use the "restricted" keyword
,D. Use the “final” keyword
,
E. Use the "sealed" keyword
,d
,7
,What is the index of the first value in an array?
,A. 1
,B. 0
,C. start
,D. null
,E. Array.length
,b
,1
,A
2 dimensional array can be described as a:
,A. Array of arrays
,B. Row of books on a shelf
,C. Cartesian plane of values
,D. Bimensional data dot-matrix
,E. None of the above
,a
,3
,Another word for Class is:
,A. Object
,B. Structure
,C. Enum
,D. All of the above
,E. None of the above
,e
,5
,A value type that consists of a set of named values is an?
,A. Enumeration
,B. Object
,C. Integrated Value Set (IVS)
,D. Integer
,E. Array
,a
,6
,Can a constructor be overloaded?
,A. Yes
,B. No
,C. Only in specific circumstances
,D. Yes -but only when exceptions are thrown
,E. Constructors can be overridden but not overloaded
,a
,4
,"String[][] fruits" is a:
,A. 1d String array
,B. 3d String array