WorksheetsCC104 SUMMATIVE TEST
Total questions: 50
Worksheet time: 50mins
A program needs to store 25,000 integer values for temporary calculations, prioritizing memory efficiency over range. Which primitive data type would be most suitable for this array, and how much memory would it approximately consume?
An 'int' array, consuming around 100 KB, offers sufficient range for calculations.
A 'short' array, consuming approximately 50 KB, provides better memory efficiency.
A 'long' array, consuming 200 KB, is ideal for comprehensive integer storage needs.
A 'byte' array, consuming only 25 KB, is the most memory-efficient choice.
Consider a Java class with an instance variable `isProcessed` (boolean) and a local variable `counter` (int) initialized to 0. If `isProcessed` is not explicitly set in the constructor, what are their initial values when an object is created?
`isProcessed` is `true`, and `counter` is `0` by explicit initialization.
Both `isProcessed` and `counter` would be `0` or `false` by default values.
`isProcessed` is `false`, and `counter` is `0` as explicitly set.
`isProcessed` is `null`, and `counter` remains uninitialized.
Evaluate the output of the following Java code snippet: `int x = 15; int y = 10; if (x > y * 2) { System.out.print("Alpha"); } else if (x == y + 5) { System.out.print("Beta"); } else { System.out.print("Gamma"); }`
The output will be "Alpha" because x is greater than y times two.
The output will be "Beta" because x equals y plus five.
The output will be "Gamma" as no conditions are met by the variables.
The code contains a syntax error preventing any output from being generated.
A program uses a `switch` statement with an integer variable `code = 2`. The cases are `case 1: System.out.print("Red"); break; case 2: System.out.print("Green"); case 3: System.out.print("Blue"); break; default: System.out.print("Unknown");`. What will be the output?
The program will output "Green" due to a direct match.
The program will output "GreenBlue" because of fall-through behavior.
The program will output "Unknown" as there is no specific break.
The program encounters an error with multiple cases matching.
A system needs to determine a user's access level. If `age` is 18 or higher, access is "Full"; otherwise, it's "Limited". Which ternary operation correctly implements this logic for `String accessLevel`?
`accessLevel = (age > 18) ? "Full" : "Limited";`
`accessLevel = (age >= 18) ? "Full" : "Limited";`
`accessLevel = "Full" ? (age >= 18) : "Limited";`
`accessLevel = (age < 18) ? "Full" : "Limited";`
Consider a `for` loop: `for (int k = 1; k < 5; k++) { System.out.print(k + " "); }`. What will be the final sequence of numbers printed to the console?
The loop will print '1 2 3 4 5' before stopping.
The output will be '1 2 3 4' because the condition is exclusive.
The loop will result in '0 1 2 3 4' if the initialization was zero.
Only '5' will be printed as the final iteration value.
A `while` loop is defined as: `int count = 3; while (count > 0) { System.out.print(count + " "); count--; }`. How many times will "count" be printed, and what is the last value printed?
It prints 4 times, with the last value being 0.
It prints 3 times, and the last value displayed is 1.
It prints 3 times, with the last value printed being 0.
It prints indefinitely, causing an infinite loop error.
A `do-while` loop is given: `int x = 5; do { x--; System.out.print(x + " "); } while (x > 2);`. What sequence of numbers will be printed by this loop?
The loop prints '5 4 3' sequentially before stopping.
The output will be '4 3 2' since x is decremented first.
The loop produces '5 4 3 2' with the condition checked after.
Only '4 3' will be printed; the loop executes twice.
Given `boolean a = true; boolean b = false; boolean c = true;`, evaluate the expression `(a && b) || c`. What is the final boolean result?
The expression evaluates to false, as 'a' AND 'b' is false.
The expression evaluates to true, because 'a' AND 'b' OR 'c' is true.
The expression results in a compilation error due to operator precedence.
The outcome is false, as 'c' does not negate the initial false.
A developer needs to store precise monetary values. Considering the information provided, which Java primitive data type is explicitly discouraged for such use cases due to precision issues?
The 'double' data type is generally the default choice for decimals.
Both 'float' and 'double' are unsuitable for precise currency calculations.
The 'long' data type offers a wide range for integral values.
Only 'float' should be avoided; 'double' offers sufficient precision.
Which statement is NOT a correct characteristic of Java's primitive data types?
They store the actual values directly in memory locations.
Types such as byte, short, int, and boolean are examples.
Their predefined sizes are determined by the language.
They are also widely known as Wrapper classes.
Which of the following statements about local variables is NOT accurate?
They are declared inside methods, constructors, or blocks.
Their visibility is restricted only within the declared block.
Local variables are implemented internally at the stack level.
They are automatically assigned default initial values by Java.
Which of these claims about instance variables is NOT entirely accurate?
They are created when an object is instantiated with 'new' keyword.
Access modifiers cannot be applied to these variables.
They hold values referenced by more than one method.
Instance variables persist as long as their associated object exists.
What characteristic described below does NOT correctly apply to class variables?
They are typically declared using the `static` keyword inside a class.
Multiple distinct copies exist for each object created from a class.
They are sometimes referred to as static variables.
Their default values mirror those of instance variables.
Regarding Java's `for` loop, which statement provided is NOT correct?
The initialization statement inside the loop header executes only once.
It consists of an initialization, a testing condition, and an update part.
A variable declared within the for loop has global scope.
The loop continues to iterate as long as its condition remains true.
Which of the following is NOT a correct characteristic of a Java `while` loop?
It is categorized as an entry-controlled loop structure.
The boolean condition is always checked before the loop body.
This loop type is suitable when the number of iterations is unknown.
The code block inside the loop will always execute at least once.
What is NOT a correct distinction of the `do-while` loop over the `while` loop?
The `do-while` loop guarantees execution of its body at least once.
It checks the boolean condition only after executing the loop statements.
The `do-while` loop is classified as an exit-controlled loop.
It is designed to run indefinitely without requiring a false condition.
Which statement about the `switch` statement in Java is NOT entirely accurate?
The `break` and `default` keywords are always mandatory.
The switch expression is evaluated only once for comparison.
Execution stops within the block when a `break` keyword is reached.
It allows selecting code blocks based on an expression's value.
Which rule does NOT accurately apply to the syntax of an `if` statement?
The keyword 'if' must be written in lowercase letters only.
An `else if` block tests a new condition if the first is false.
Uppercase variations like 'If' or 'IF' are syntactically acceptable.
An `else` statement executes its code if the initial condition is false.
Which of the following is NOT correctly categorized as a non-primitive data type?
Classes are considered non-primitive types in Java.
Interfaces are included within the non-primitive data types category.
Arrays represent examples of non-primitive data structures.
The `long` data type is classified as non-primitive.
An array `myNumbers` is declared and instantiated to hold 15 integer elements. What is the correct index to access the ninth element in this array?
The index to access the ninth element would be 8.
The index to access the ninth element would be 9.
The index to access the ninth element would be 14.
The index to access the ninth element would be 15.
An array `fruits` is initialized as `{"apple", "banana", "cherry", "date"}`. Then, `fruits[2] = "grape";` is executed. What fruit is stored at the index representing the third position after these operations?
The fruit "apple" will be stored at the third position.
The fruit "banana" will be stored at the third position.
The fruit "grape" will be stored at the third position.
The fruit "cherry" will be stored at the third position.
A two-dimensional array named `grid` is declared as `int[][] grid = new int[4][5];`. How many total integer elements can this array store, and what are the valid row indices?
It stores 20 elements, with valid row indices 0 through 4.
It stores 9 elements, with valid row indices 0 through 3.
It stores 20 elements, with valid row indices 0 through 3.
It stores 9 elements, with valid row indices 0 through 4.
A programmer needs an array to store monthly sales data, where each month might have a different number of daily entries. Which type of array would be most suitable for efficiently representing this varying daily entry structure?
A one-dimensional array would adequately store all the monthly sales data.
A standard two-dimensional array offers the most efficient storage solution.
A ragged array allows different numbers of daily entries for each month.
A multidimensional array, with fixed dimensions, is generally preferred.
A developer wants to reserve memory space for 8 integers in an array named `values` without immediately assigning initial content. Which code snippet correctly performs this memory allocation?
`int values[]; values = {1,2,3,4,5,6,7,8};`
`int[] values = new int[8];`
`int[] values;`
`values[0] = 5;`
What is the direct capability of a standard Java array when attempting to remove an element and reduce its size?
Java arrays provide a built-in `remove()` method to shrink size directly.
Elements can be directly removed, and the array automatically resizes.
Array size is static; direct removal and size reduction are not possible.
A special keyword allows array elements to be removed dynamically.
If you execute `int arraySize = data.length;`, what value will the `arraySize` variable hold?
The `arraySize` variable will contain the value 5.
The `arraySize` variable will contain the value 6.
The `arraySize` variable will contain the value 0.
The `arraySize` variable will contain the value 600.
Alice wants to send Bob the confidential message "HELLO". She decides to encrypt it using a simple Caesar Cipher with a right shift of 3 applied to each character in the message. After encryption, Bob receives the ciphertext. What is the ciphertext for the message "HELLO"?
A) KHOOR
B) EBIIL
C) IFMMP
D) GDKKN
A) KHOOR
B) EBIIL
C) IFMMP
D) GDKKN
How many distinct memory locations are reserved to store the `double` values themselves?
A total of 7 memory locations are reserved for the values.
A total of 12 memory locations are reserved for the values.
A total of 3 memory locations are reserved for the values.
A total of 4 memory locations are reserved for the values.
To efficiently manage and calculate GPAs for each student, which array structure is most appropriate for this data?
A one-dimensional array would simplify storing all the student grades.
A standard two-dimensional array with fixed rows and columns is ideal.
A ragged array allows flexible storage for varying course counts per student.
Multiple separate one-dimensional arrays, one for each student, are best.
An array is generally NOT described by which of the following characteristics?
Storing multiple values using a single variable name reference.
Holding a collection of elements that are all of the same data type.
Allocating memory locations that are always entirely separate and non-contiguous.
Allowing access to individual elements using a numerical index system.
Which statement regarding the index of an array is NOT accurate?
It is a numerical value linked to each specific element in the array.
Used primarily for accessing individual elements within the array structure.
Always starts its counting sequence from the integer value of one.
Progresses through positive integers, indicating the order of elements.
Among the following, which is NOT explicitly listed as a type of array?
One-dimensional arrays featuring a single index for element access.
Multi-dimensional arrays, including the two-dimensional variant.
Self-expanding arrays that automatically adjust their size dynamically.
Ragged arrays, allowing member arrays to have differing sizes or lengths.
Instantiation of an array typically does NOT involve which specific action?
Employing the 'new' keyword to allocate a defined memory space.
Defining the specific length or size that the array will occupy.
Assigning initial data values to all the elements within the array.
Combining a declaration with an intention to create memory allocation.
What is NOT a correct method or principle when changing array elements?
Assigning a new value directly to an element via its specific index.
Replacing the old value at an index with the newly assigned data.
Allowing the user to input both the index and the new value.
Elements remain fixed once set; no direct modification is possible later.
When dealing with Java arrays, what is NOT a characteristic of removing elements?
Java arrays lack a direct, built-in method specifically for removing elements.
The size of instantiated Java arrays cannot be changed or reduced directly.
Employing various workarounds is often necessary to achieve element removal.
Deleting an element automatically shrinks the array's memory allocation.
A one-dimensional array is NOT characterized by which of the following?
Being an array that only possesses a single index for access.
Requiring two distinct indices to identify a specific element location.
Storing elements consecutively in a single, linear sequence in memory.
Its declaration potentially including specifying an initial length or size.
The length() method, when applied to an array, is NOT used for which purpose?
Determining the current total number of elements stored within the array.
Ascertaining the allocated memory size that the array presently occupies.
Dynamically altering the actual capacity of the array after instantiation.
Retrieving the array's defined boundary for iteration or access operations.
Which statement is NOT a defining characteristic of a Ragged Array?
It comprises multiple arrays, forming an array of arrays structure.
Each of its member arrays must maintain an identical, uniform size.
It is also recognized and referred to by the alternative name 'jagged array.'
Allowing different numbers of columns for its various individual rows.
Regarding memory storage, which statement is NOT true when comparing arrays and normal variables?
Arrays store all entered elements in contiguous parts of memory.
Normal variables inherently retain a history of multiple previously entered values.
Arrays facilitate retrieval of multiple records from a single object.
A normal variable typically holds only the most recent or last assigned value.
Which statement INCORRECTLY describes the core concept of Cryptography?
It primarily focuses on securing information and communications through the use of codes.
It prevents unauthorized access, ensuring only intended recipients can understand messages.
It primarily focuses on breaking codes and ciphers, not securing data.
It involves mathematical concepts and algorithms for cryptographic key generation.
Which of the following is NOT a fundamental feature of cryptography?
Confidentiality, ensuring only the intended person can access the information.
Integrity, preventing information modification without any detection of alteration.
Non-repudiation, allowing the creator to deny sending the information at a later stage.
Authentication, confirming the identities of both the sender and the receiver.
Which statement about Symmetric Key Cryptography is NOT true?
It uses a single common key for both encrypting and decrypting messages.
Symmetric Key Systems are generally known for being faster and simpler.
The main issue is securely exchanging the shared key between sender and receiver.
It mandates different public and private keys for encryption and decryption tasks.
Which statement is INCORRECT regarding Hash Functions in cryptography?
Hash functions do not involve the usage of any key in their algorithms.
A hash value with a fixed length is calculated based on the plaintext.
It is possible to recover the original plaintext contents from its hash value.
Many operating systems frequently use hash functions to encrypt user passwords.
Which of the following is NOT a characteristic of Asymmetric Key Cryptography?
It uses a pair of keys, one public for encryption and one private for decryption.
The public key can be widely known, but only the private key decrypts the message.
The intended receiver can decode messages because only they possess the private key.
The public key and its corresponding private key are always identical.
Which statement does NOT accurately describe the process of decryption?
It converts secretly coded data back into its original, understandable form.
Decryption allows the original message to be read and comprehended.
It signifies converting plain text into an encrypted, unreadable secret code.
It is the inverse process of encryption, restoring cipher text to plaintext.
Which statement about the Caesar Ciphertext is INCORRECT?
It is recognized as one of the earliest and most straightforward substitution ciphers.
Each letter in the plaintext is shifted a fixed number of positions down the alphabet.
It employs multiple substitution alphabets based on a repeating keyword.
The cipher utilizes a cyclic property for shifts extending beyond the alphabet's end.
Which of the following is NOT a characteristic of the Vigenère Ciphertext?
It is a polyalphabetic substitution cipher, using multiple substitution alphabets.
The encryption process involves using a Vigenère square or Vigenère table.
Encryption always applies a single, fixed letter shift to all plaintext.
The alphabet used at each point in encryption depends on a repeating keyword.
Based on the provided encryption example for Vigenère Ciphertext, which statement is INCORRECT?
The first letter of the plaintext is paired with the first letter of the key.
The intersection of the plaintext's column and the keyword's row gives the ciphertext letter.
The keyword letter determines the column, and the plaintext letter specifies the row.
The process is repeated, pairing plaintext letters with the repeating keyword to encrypt.
Which of the following descriptions is NOT accurate for Cryptanalysis?
Cryptanalysis is focused on the scientific study of keeping information confidential.
It is widely recognized as the 'art of breaking codes and ciphers' effectively.
Its main objective is to retrieve original messages from encrypted ciphertext.
It is distinct from cryptography, which primarily aims to secure communications.
