1.
What is the value of z after executing this sequence (check indentation)?
int x = 100, y = 50, z = -1;
if ( x + y > 50)
if ( x + y < 100)
z = 0;
else
z = 1;
Correct Answer
C. 1
Explanation
The value of z is 1 because the first if statement evaluates to true since 100 + 50 is greater than 50. Then, the nested if statement also evaluates to true since 100 + 50 is less than 100. Therefore, z is assigned a value of 0.
2.
What does the leading + sign at the start of a method indicate?
Correct Answer
B. A class method
Explanation
The leading + sign at the start of a method indicates that it is a class method. Class methods are methods that are associated with the class itself rather than with an instance of the class. They can be called on the class directly, without creating an instance of the class.
3.
What is wrong with this sequence of code?
sum = 100;
int sum;
Correct Answer
B. A variable must be declared before it can be used
Explanation
In this sequence of code, the variable "sum" is being assigned a value of 100 before it is declared as an integer using the "int" keyword. In programming, variables must be declared before they can be used. Therefore, the correct answer is "A variable must be declared before it can be used."
4.
Given
int a = 10, b = 20, c;
b *= a + 5;
What is the resulting value of b?
Correct Answer
C. 300
Explanation
The resulting value of b is 300. The expression "b *= a + 5" is equivalent to "b = b * (a + 5)". Since a is 10, the expression becomes "b = b * (10 + 5)". Since b is initially 20, the expression further simplifies to "b = 20 * 15", which evaluates to b = 300.
5.
What is the file extension name used for Objective-C code?
Correct Answer
C. .m
Explanation
The file extension name used for Objective-C code is .m. This extension is commonly used in Objective-C programming to indicate that the file contains code written in the Objective-C language. Other file extensions mentioned in the options, such as .cpp, .pl, and .c, are used for different programming languages like C++, Perl, and C. Therefore, .m is the correct answer for the file extension name used for Objective-C code.
6.
What is the value of s after executing this loop:
int i = 0, s = 0;
while (i < 5)
s += ++i;
Correct Answer
B. 15
Explanation
The value of 's' is 15 after executing the loop because the loop iterates 5 times. In each iteration, 'i' is incremented by 1 using the pre-increment operator (++i), and then added to 's'. So, in the first iteration, 'i' becomes 1 and 's' becomes 1. In the second iteration, 'i' becomes 2 and 's' becomes 3. This process continues until the fifth iteration, where 'i' becomes 5 and 's' becomes 15.
7.
Which value is not equivalent to the others?
Correct Answer
D. 0XE5
Explanation
The value 0xE5 is not equivalent to the others because it is represented in hexadecimal notation, while the other values are represented in decimal or octal notation.
8.
Which is an example of an invalid variable name?
Correct Answer
B. X123$
Explanation
The variable name "x123$" is an example of an invalid variable name because it starts with a special character ($) which is not allowed in variable names. In most programming languages, variable names can only start with a letter or an underscore, not with a special character.
9.
What is a local variable that has no default initial value and does not retain its value through method calls?
Correct Answer
B. An auto variable
Explanation
An auto variable is a local variable that has no default initial value and does not retain its value through method calls. Unlike global and static variables, which have default initial values and can retain their values across method calls, an auto variable is only accessible within the scope of the method in which it is declared and must be explicitly assigned a value before it can be used. Therefore, the correct answer is an auto variable.
10.
What should you do If you want to return an object back to the caller of your method and you want to mark the object for a later release?
Correct Answer
A. Autorelease it before returning
Explanation
If you want to return an object back to the caller of your method and mark it for a later release, you should autorelease it before returning. Autoreleasing an object means that it will be automatically released at a later time, allowing the caller to use the object without worrying about memory management. This is useful when you want to pass ownership of the object to the caller, but still want to ensure that it will be released when it is no longer needed.