Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Programming Exam Prep: PRO 192 Study Guide, Exams of Object Oriented Programming

A study guide for pro 192, focusing on java programming concepts. It includes multiple-choice questions covering topics such as data types, access modifiers, serialization, and array manipulation. The guide provides a series of questions and answers designed to test understanding of java fundamentals and object-oriented programming principles. It is useful for students preparing for exams or quizzes on java programming. The questions cover a range of topics, including variable declarations, method calls, and the behavior of java code snippets. The guide also touches on more advanced concepts such as garbage collection and locale-sensitive text formatting. The questions are designed to assess understanding of java syntax, semantics, and best practices. The guide is a valuable resource for anyone looking to improve their java programming skills and prepare for exams or quizzes.

Typology: Exams

2024/2025

Available from 06/01/2025

GlobalStudyVault
GlobalStudyVault 🇺🇸

574 documents

1 / 217

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PRO 192 FULL EXAM PREP STUDY GUIDE |
100% Correct | Verified Version
A, B, D - - - - ✔✔Which of the following are valid declarations? Assume java.util.* is imported. (choose 3)
A. Vector<Map> v;
B. Set<String> s;
C. Map<String> m;
D. Map<String, String> m;
A - - - - ✔✔You can determine all the keys in a Map in which of the following ways?
A By getting a Set object from the Map and iterating through it.
B By iterating through the Iterator of the Map.
C By enumerating through the Enumeration of the Map.
D By getting a List from the Map and enumerating through the List.
E You cannot determine the keys in a Map
D - - - - ✔✔What keyword is used to prevent an object from being serialized?
A private
B volatile
C protected
D transient
E None of the above
A - - - - ✔✔An abstract class can contain methods with declared bodies.
A True
B False
E - - - - ✔✔Select the order of access modifiers from least restrictive to most restrictive.
PRO 192 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Java Programming Exam Prep: PRO 192 Study Guide and more Exams Object Oriented Programming in PDF only on Docsity!

PRO 192 FULL EXAM PREP STUDY GUIDE |

100% Correct | Verified Version

A, B, D - - - - ✔✔Which of the following are valid declarations? Assume java.util.* is imported. (choose 3) A. Vector v; B. Set s; C. Map m; D. Map<String, String> m; A - - - - ✔✔You can determine all the keys in a Map in which of the following ways? A⦁ By getting a Set object from the Map and iterating through it. B⦁ By iterating through the Iterator of the Map. C⦁ By enumerating through the Enumeration of the Map. D⦁ By getting a List from the Map and enumerating through the List. E⦁ You cannot determine the keys in a Map D - - - - ✔✔What keyword is used to prevent an object from being serialized? A ⦁ private B ⦁ volatile C ⦁ protected D ⦁ transient E ⦁ None of the above A - - - - ✔✔An abstract class can contain methods with declared bodies. A ⦁ True B ⦁ False E - - - - ✔✔Select the order of access modifiers from least restrictive to most restrictive.

A ⦁ public, private, protected, default B ⦁ default, protected, private, public C ⦁ public, default, protected, private D ⦁ default, public, protected, private E ⦁ public, protected, default, private C - - - - ✔✔Which access modifier allows you to access method calls in libraries not created in Java? A ⦁ public B ⦁ static C ⦁ native D ⦁ transient E ⦁ volatile D - - - - ✔✔Which of the following statements are true? (Select all that apply.) A ⦁ A final object's data cannot be changed. B ⦁ A final class can be subclassed. C ⦁ A final method cannot be overloaded. D ⦁ A final object cannot be reassigned a new address in memory. E ⦁ None of the above. A - - - - ✔✔The keyword extends refers to what type of relationship? A ⦁ "is a" B ⦁ "has a" C ⦁ "was a" D ⦁ "will be a" E ⦁ None of the above B - - - - ✔✔Which of the following keywords is used to invoke a method in the parent class?

D ⦁ The code does not compile. E ⦁ None of the above. D - - - - ✔✔What is the value of x after the following operation is performed? x = 23 % 4; A. 23 B. 4 C. 5. D. 3 E. 5 C - - - - ✔✔Given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? boolean b = true; for (;;) { if (b) { } // do something } A ⦁ stop B ⦁ continue C ⦁ break D ⦁ None of the above B - - - - ✔✔What method call is used to tell a thread that it has the opportunity to run?

A ⦁ wait() B ⦁ notify() C ⦁ start() D ⦁ run() A - - - - ✔✔Given the following code, which of the results that follow would you expect?

  1. package mail; 2. interface Box { protected void open(); void close(); public void empty(); } A ⦁ The code will not compile because of line 4. B ⦁ The code will not compile because of line 5. C ⦁ The code will not compile because of line 6. D ⦁ The code will compile C - - - - ✔✔Assertions are used to enforce all but which of the following? A ⦁ Preconditions B ⦁ Postconditions C ⦁ Exceptions D ⦁ Class invariants B - - - - ✔✔The developer can force garbage collection by calling System.gc(). A ⦁ True B ⦁ False

A. boolean, char, byte, double B. byte, int, float, char C. char, short, long, float D. char, int, float, long E. None of the above D - - - - ✔✔23. Which class provides locale-sensitive text formatting for date and time information? A. java.util.TimeFormat B. java.util.DateFormat C. java.text.TimeFormat D. java.text.DateFormat B - - - - ✔✔24. The following line of code is valid. int x = 9; byte b = x; A. True B. False A, B, C - - - - ✔✔25. Which of the following code snippets compile? (choose 3) A. Integer i = 7; B. Integer i = new Integer(5); int j = i; C. byte b = 7; D. int i = 7; byte b = i; E. None of the above D - - - - ✔✔26. What will be the output of the following code? public class StringTest { public static void main(String [] a) { String s1 = "test string"; String s2 = "test string"; if (s1 == s2) {

System.out.println("same"); } else { System.out.println("different"); } } } A. The code will compile but not run. B. The code will not compile. C. "different" will be printed out to the console. D. "same" will be printed out to the console. E. None of the above B - - - - ✔✔27. Java arrays always start at index 1. A. True B. False C - - - - ✔✔28. Which of the following statements accurately describes how variables are passed to methods? A. Arguments are always passed by value. B. Arguments are always passed by reference. C. Arguments that are primitive type are passed by value. D. Arguments that are passed with the & operator are passed by reference. D - - - - ✔✔29. How do you change the value that is encapsulated by a wrapper class after you have instan- tiated it? A. Use the setXXX() method defined for the wrapper class. B. Use the parseXXX() method defined for the wrapper class. C. Use the equals() method defined for the wrapper class. D. None of the above.

D - - - - ✔✔4. If all three top-level elements occur in a source file, they must appear in which order? A. Imports, package declarations, classes/interfaces/enums B. Classes/interfaces/enums, imports, package declarations C. Package declaration must come first; order for imports and class/interfaces/enum definitions is not significant D. Package declaration, imports, class/interface/enum definitions. E. Imports must come first; order for package declarations and class/interface/enum definitions is not significant A, E - - - - ✔✔5. Consider the following line of code: int[] x = new int[25]; After execution, which statements are true? (Choose 2) A. x[24] is 0 B. x[24] is undefined C. x[25] is 0 D. x[0] is null E. x.length is 25 D - - - - ✔✔6. Consider the following application:

  1. class Q6 {
  2. public static void main(String args[]) {
  3. Holder h = new Holder();
  4. h.held = 100;
  5. h.bump(h);
  6. System.out.println(h.held);
  7. }
  8. } 9.
  9. class Holder {
  1. public int held;
  2. public void bump(Holder theHolder) {
  3. theHolder.held++; }
  4. }
  5. } What value is printed out at line 6? A. 0 B. 1 C. 100 D. 101 C - - - - ✔✔7. Consider the following application:
  6. class Q7 {
  7. public static void main(String args[]) {
  8. double d = 12.3;
  9. Decrementer dec = new Decrementer();
  10. dec.decrement(d);
  11. System.out.println(d);
  12. }
  13. } 9.
  14. class Decrementer {
  15. public void decrement(double decMe) {
  16. decMe = decMe - 1.0;
  17. }
  18. }

B - - - - ✔✔11. Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file? A. Compilation takes no additional time. B. Compilation takes slightly more time. C. Compilation takes significantly more time. A - - - - ✔✔12. Suppose a source file contains a large number of import statements and one class definition. How do the imports affect the time required to load the class? A. Class loading takes no additional time. B. Class loading takes slightly more time. C. Class loading takes significantly more time. A, C - - - - ✔✔13. Which of the following are legal import statements? (choose 2) A. import java.util.Vector; B. static import java.util.Vector.; C. import static java.util.Vector.; D. import java.util.Vector static; B, C - - - - ✔✔14. Which of the following may be statically imported? (Choose 2) A. Package names B. Static method names C. Static field names D. Method-local variable names C - - - - ✔✔15. What happens when you try to compile and run the following code? public class Q15 { static String s;

public static void main(String[] args) { System.out.println(">>" + s + "<<"); } } A. The code does not compile B. The code compiles, and prints out >><< C. The code compiles, and prints out >>null<< C, D - - - - ✔✔16. Which of the following are legal? (Choose 2) A. int a = abcd; B. int b = ABCD; C. int c = 0xabcd; D. int d = 0XABCD; E. int e = 0abcd; F. int f = 0ABCD; A, B - - - - ✔✔17. Which of the following are legal? (Choose 2) A. double d = 1.2d; B. double d = 1.2D; C. double d = 1.2d5; D. double d = 1.2D5; C - - - - ✔✔18. Which of the following are legal? A. char c = 0x1234; B. char c = \u1234; C. char c = '\u1234';

B. int x = 6; if (!(x > 3)) {} C. int x = 6; x = ~x; A - - - - ✔✔3. Which of the following expressions results in a positive value in x? A. int x = - 1; x = x >>> 5; B. int x = - 1; x = x >>> 32; C. byte x = - 1; x = x >>> 5; D. int x = - 1; x = x >> 5; A, C - - - - ✔✔4. Which of the following expressions are legal? (Choose 2) A. String x = "Hello"; int y = 9; x += y; B. String x = "Hello"; int y = 9; if (x == y) {} C. String x = "Hello"; int y = 9; x = x + y; D. String x = "Hello"; int y = 9; y = y + x; A - - - - ✔✔5. What is - 8 % 5? A. - 3 B. 3 C. - 2 D. 2 B - - - - ✔✔6. What is 7 % - 4? A. - 3 B. 3 C. - 4 D. 4 B - - - - ✔✔7. What results from running the following code?

  1. public class Xor {
  2. public static void main(String args[]) {
  3. byte b = 10; // 00001010 binary
  4. byte c = 15; // 00001111 binary
  5. b = (byte)(b ^ c);
  6. System.out.println("b contains " + b);
  7. }
  8. } A. The output: b contains 10 B. The output: b contains 5 C. The output: b contains 250 D. The output: b contains 245 C - - - - ✔✔8. What results from attempting to compile and run the following code?
  9. public class Conditional {
  10. public static void main(String args[]) {
  11. int x = 4;
  12. System.out.println("value is " +
  13. ((x > 4)? 99.99 : 9));
  14. }
  15. } A. The output: value is 99. B. The output: value is 9 C. The output: value is 9. D. A compiler error at line 5 B - - - - ✔✔9. What does the following code do?

C. float D. You can't add a short to a float. A - - - - ✔✔14. Which statement is true about the following method? int selfXor(int i) { return i ^ i; } A. It always returns 0. B. It always returns 1. C. It always an int where every bit is 1. D. The returned value varies depending on the argument. D - - - - ✔✔15. Which of the following operations might throw an ArithmeticException? A. >> B. >>> C. << D. None of these D - - - - ✔✔16. Which of the following operations might throw an ArithmeticException? A. + B. - C. * D. / E. None of these D - - - - ✔✔17. What is the return type of the instanceof operator? A. A reference B. A class

C. An int D. A boolean A - - - - ✔✔18. Which of the following may appear on the left-hand side of an instanceof operator? A. A reference B. A class C. An interface D. A variable of primitive type A, B - - - - ✔✔19. Which of the following may appear on the right-hand side of an instanceof operator? (Choose 2) A. A reference B. A class C. An interface D. A variable of primitive type E. The name of a primitive type D - - - - ✔✔20. What is - 50 >> 1? A. A negative number with very large magnitude. B. A positive number with very large magnitude. C. - 100 D. - 25 E. 100 F. 25 A, D, E - - - - ✔✔1. Which of the following declarations are illegal? (Choose 3) A. default String s; B. transient int i = 41; C. public final static native int w();