Objective C & OOP Examination 1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Indianou
I
Indianou
Community Contributor
Quizzes Created: 4 | Total Attempts: 2,212
| Attempts: 1,456 | Questions: 100
Please wait...
Question 1 / 100
0 %
0/100
Score 0/100
1. The primary root object for the Foundation framework is called NSObject

Explanation

The primary root object for the Foundation framework is called NSObject. This means that NSObject serves as the base class for most classes in the Foundation framework. It provides essential functionality and behaviors that are inherited by other classes in the framework. As a result, NSObject is a fundamental component in the Foundation framework and plays a crucial role in the overall structure and functionality of the framework.

Submit
Please wait...
About This Quiz
Object Oriented Programming Quizzes & Trivia

This examination assesses knowledge in Objective C and fundamental Object-Oriented Programming (OOP) concepts. It covers memory management, class categories, and initialization protocols, essential for developers to build robust... see moresoftware applications efficiently. see less

2. Given an object with an instance variable called numerator and synthesized accessor methods the following two lines of code achieve the same purpose: fract.numerator = 10; [fract setNumerator: 10];

Explanation

The given answer is true because both lines of code are setting the value of the numerator instance variable to 10. The first line uses the synthesized accessor method to directly set the value, while the second line uses a custom setter method called setNumerator to achieve the same purpose. Therefore, both lines of code have the same effect and achieve the same purpose.

Submit
3. The id data type can be used for any object type; it is a generic object data type.

Explanation

The statement is true because the id data type in Python can be used to represent any object type. It is a generic object data type that can hold the unique identifier of any object in memory. This allows for flexibility in programming as the id data type can be used to store references to objects of different types without needing to specify the specific type beforehand.

Submit
4. When the retain count on an object reaches 0, the object gets sent a dealloc message.

Explanation

When the retain count on an object reaches 0, it means that there are no more references to that object and it is no longer needed. At this point, the object gets sent a dealloc message, which is a method that releases any resources or memory that the object was holding onto. This allows the object to clean up after itself and free up any allocated memory, making it available for other objects to use. Therefore, the statement "When the retain count on an object reaches 0, the object gets sent a dealloc message" is true.

Submit
5. A respondsToSelector: message can be sent to an object to see if it can respond to a particular method.

Explanation

The statement is true because in Objective-C, the respondsToSelector: message can be used to check if an object can respond to a specific method. This is commonly used when you want to avoid calling a method on an object that may not have implemented it, preventing runtime errors. By using respondsToSelector:, you can safely check if the object can respond to the method before actually calling it.

Submit
6. You own an object that you copy

Explanation

The statement "You own an object that you copy" is true. When you copy an object, you create a new instance of that object which you then own. This means that you have the ability to modify or manipulate the copied object without affecting the original object. Therefore, the answer is true.

Submit
7. The conformsToProtocol: method can be used to see if an object belongs to a class that implements a particular protocol

Explanation

The conformsToProtocol: method is a built-in method in Objective-C that allows us to check if an object belongs to a class that implements a specific protocol. It returns a Boolean value, true if the object conforms to the protocol and false otherwise. This method is useful when we want to ensure that an object meets certain requirements defined by a protocol before performing certain operations or accessing specific methods or properties. Therefore, the given statement is true.

Submit
8. You can add more than one category to a class.

Explanation

In object-oriented programming, it is possible to assign a class to multiple categories or classifications. This is known as multiple inheritance or multiple classification. It allows a class to inherit properties and behaviors from more than one parent class. This can be useful in situations where a class needs to have characteristics from different categories. Therefore, the statement "You can add more than one category to a class" is true.

Submit
9. In general, you are responsible for releasing an object created with the copy method.

Explanation

When an object is created using the copy method, it creates a new instance of the object that is a copy of the original object. This means that the new object has its own memory space and is independent of the original object. Therefore, it is the responsibility of the programmer to release the memory occupied by the copied object when it is no longer needed. This can be done by explicitly calling the appropriate release or deallocation method. Hence, the statement "In general, you are responsible for releasing an object created with the copy method" is true.

Submit
10. In general, when you add an object to a Foundation array, its retain count gets increased by 1.

Explanation

When an object is added to a Foundation array, its retain count is increased by 1. This means that the object is being held in memory by the array and will not be deallocated until the retain count reaches 0. This is important for memory management in Objective-C, as it ensures that objects are not prematurely released while they are still being used by other parts of the program. Therefore, the statement "True" is correct.

Submit
11. In general, when you add an object to a Foundation array, its retain count gets increased by 1.

Explanation

When an object is added to a Foundation array, its retain count is increased by 1. This means that the array is now holding a reference to the object, preventing it from being deallocated from memory. This is a fundamental concept in memory management in Objective-C and ensures that objects are kept alive as long as they are needed. By increasing the retain count, the array is indicating that it has ownership of the object and will release it when it is no longer needed. Therefore, the statement "True" is correct.

Submit
12. In the general form of the for statement for ( e1; e2; e3 )    statement; e2 is evaluated before statement is executed.

Explanation

In the general form of the for statement, e2 is evaluated before the statement is executed. This means that the condition specified in e2 is checked first, and if it evaluates to true, then the statement is executed. If e2 evaluates to false, the loop is not executed at all. Therefore, the correct answer is true.

Submit
13. The @private directive restricts access to instance variables to methods in the class; subclasses cannot access the variables directly.

Explanation

The @private directive is used in object-oriented programming languages to restrict access to instance variables. When applied to a variable, it means that only methods within the class can access it, while subclasses cannot access the variable directly. This helps maintain encapsulation and prevents subclasses from directly modifying or accessing the instance variables of the superclass. Therefore, the statement "The @private directive restricts access to instance variables to methods in the class; subclasses cannot access the variables directly" is true.

Submit
14. When you use alloc to create a new object, you should release the object when you're done using it

Explanation

When using the "alloc" method to create a new object in programming, memory is allocated for that object. To prevent memory leaks and optimize memory usage, it is necessary to release the object when it is no longer needed. This can be done by using the "release" or "dealloc" method. Therefore, the statement "When you use alloc to create a new object, you should release the object when you're done using it" is true.

Submit
15. What file name extension is used for Objective-C code?

Explanation

The correct answer is .m. In Objective-C, the file name extension used for Objective-C code is .m. This extension is commonly used to indicate that the file contains Objective-C code, similar to how .cpp is used for C++ code and .c is used for C code. The .m extension helps developers and compilers identify the file as containing Objective-C code and allows for proper compilation and execution of the code.

Submit
16. A newly allocated object should always be initialized

Explanation

When a new object is allocated in a program, it means that memory is set aside for that object. However, this memory is not automatically filled with any specific values. Initialization is the process of assigning initial values to the object's variables or attributes. It is important to initialize a newly allocated object to ensure that all its variables have valid values before they are used in the program. This helps prevent any unexpected behavior or errors that may occur due to uninitialized variables. Therefore, the statement that a newly allocated object should always be initialized is true.

Submit
17. A class gets sent an initialize message when the class gets referenced for the first time.

Explanation

When a class gets referenced for the first time, it receives an initialize message. This message is sent to the class to perform any necessary setup or initialization tasks before it can be used. Therefore, the statement "A class gets sent an initialize message when the class gets referenced for the first time" is true.

Submit
18. An instance of a class is known as

Explanation

An instance of a class is known as an object. In object-oriented programming, a class is a blueprint for creating objects. An object is an instance of a class, meaning it is a specific realization or occurrence of the class. Objects have their own unique set of properties and behaviors, which are defined by the class they belong to. Therefore, an object is the correct term for an instance of a class.

Submit
19. The following: @interface Fraction (MathOps)   ... @end

Explanation

This code snippet is defining a category called MathOps for the Fraction class. A category allows you to add additional methods to an existing class without subclassing it. By using this category, you can add new methods to the Fraction class specifically for mathematical operations.

Submit
20. What is wrong with this sequence of code? sum = 100; int sum;

Explanation

The code is incorrect because the variable "sum" is being assigned a value before it is declared. In programming, variables must be declared before they can be used.

Submit
21. It's okay to override init, but not considered wise to override alloc.

Explanation

Overriding the `init` method in a class allows customization of the initialization process for instances of that class. This can be useful to set default values or perform additional setup tasks. However, overriding the `alloc` method, which is responsible for memory allocation and initialization of an object, can lead to unexpected behavior and potential memory leaks. It is generally recommended to avoid overriding `alloc` unless there is a specific need for it. Therefore, the statement that it's okay to override `init` but not considered wise to override `alloc` is true.

Submit
22. In general, you are responsible for releasing an object created with the copy method.

Explanation

When an object is created using the copy method, it creates a new instance of the object with the same values as the original object. In general, it is the responsibility of the programmer to release or deallocate the memory used by the copied object when it is no longer needed. Therefore, the statement "In general, you are responsible for releasing an object created with the copy method" is true.

Submit
23. The method names print and print: refer to two different methods.

Explanation

The statement is true because the method names "print" and "print:" have different syntaxes. In many programming languages, including Java and Python, the presence of a colon (:) in a method name indicates that it takes parameters or arguments. Therefore, "print" and "print:" are considered as two distinct methods with potentially different functionalities.

Submit
24. The dealloc method is automatically called when an object's memory can be freed.

Explanation

The dealloc method in object-oriented programming is responsible for freeing the memory occupied by an object. When an object is no longer needed or goes out of scope, the dealloc method is automatically called to release the memory allocated to that object. Therefore, the statement "The dealloc method is automatically called when an object's memory can be freed" is true.

Submit
25. Web-based apps require users to connect to the website that host the application in order to run them.

Explanation

Web-based apps are designed to run on a web browser, which means users need to connect to the website hosting the application to access and use it. Unlike traditional software that is installed directly on a device, web-based apps rely on an internet connection to function. This allows users to access the app from any device with a web browser, making it convenient and accessible from anywhere. Therefore, the statement "Web-based apps require users to connect to the website that hosts the application in order to run them" is true.

Submit
26. If s is an NSString object, the expression [s length] - 1

Explanation

The expression [s length] - 1 gives the number of characters in the string minus 1. The [s length] method returns the length of the NSString object, and subtracting 1 from it gives the number of characters in the string minus 1.

Submit
27. If you omit a break statement at the end of a case in a switch statement, then execution will fall down into the next case.

Explanation

If a break statement is omitted at the end of a case in a switch statement, it means that the code will not exit the switch statement and will continue executing the code in the next case. This is known as "falling through" to the next case. It can be useful in certain situations where you want to execute multiple cases sequentially without having to repeat the code. However, it can also lead to unexpected behavior if not used carefully.

Submit
28. A static variable will retain its value from one method call to the next.

Explanation

A static variable is a variable that is shared by all instances of a class. It is not tied to a specific object and retains its value across method calls. This means that when a method is called multiple times, the static variable will maintain the same value throughout those calls. Therefore, the given answer "True" is correct.

Submit
29. What is the value assigned to m? #define M(x,y) (((x)>(y)) ?   (x) : (y)) ... int x = 10, y = 20, m; m = M (x, y);

Explanation

The value assigned to m is 20. In the macro definition M(x,y), it compares the values of x and y using the greater than operator. If x is greater than y, it returns x. Otherwise, it returns y. In this case, since x is not greater than y (10 is not greater than 20), the value assigned to m is y, which is 20.

Submit
30. The first character in a string has an index number of 1

Explanation

The given statement is false. In most programming languages, the index of the first character in a string starts at 0, not 1. This means that the first character in a string would have an index number of 0, not 1.

Submit
31. The main difference between NSString and NSMutableString objects is

Explanation

The main difference between NSString and NSMutableString objects is that the contents of NSString objects cannot be changed once they are set, while the contents of NSMutableString objects can be modified. This means that NSString objects are immutable, while NSMutableString objects are mutable. Therefore, the correct answer is "The contents of the former cannot be changed while the latter can."

Submit
32. A class definition does not contain

Explanation

A class definition does not contain a main routine because the main routine is typically found in the program that uses the class, rather than within the class itself. The main routine is the entry point of the program and is responsible for starting the execution of the program. It is separate from the class definition and is used to create objects of the class and call its methods.

Submit
33. If x is an integer, the expression (x > 0) ? 1 :    ((x == 0) ? 0 : -1)

Explanation

The given expression is a conditional (ternary) operator that checks the value of x. If x is greater than 0, it returns 1. If x is equal to 0, it returns 0. If x is less than 0, it returns -1. Therefore, the expression has the value 1 if x is greater than 0, has the value 0 if x is equal to 0, and has the value -1 if x is less than 0. Hence, the correct answer is "all of the above."

Submit
34. What is the value of sum after executing this loop: for (int i = 0, sum = 0;      i < 10; i += 2)    sum += i;

Explanation

The loop starts with i = 0 and sum = 0. In each iteration, i is incremented by 2 and added to sum. The loop stops when i reaches 10. Therefore, the loop will execute 5 times with i taking the values 0, 2, 4, 6, and 8. The sum of these values is 20, which is the final value of sum after executing the loop.

Submit
35. Data encapsulation means

Explanation

Data encapsulation refers to the practice of bundling data and the methods that operate on that data into a single unit, known as an object. This answer correctly states that data encapsulation involves storing an object's data in its instance variables, which are the variables that hold the object's data, and providing access to that data through its methods. By encapsulating the data within the object, it ensures that the data is protected and can only be accessed and modified through the defined methods, promoting data integrity and security.

Submit
36. In general, this sequence [foo retain]; [pool drain]; guarantees the existence of the object foo past the draining of the autorelease pool pool.

Explanation

The given code sequence includes a retain statement for the object foo and a drain statement for the autorelease pool pool. The retain statement increases the retain count of the object, ensuring that it will not be deallocated immediately. The drain statement releases all objects in the autorelease pool, which would normally result in the object foo being released as well. However, since the retain statement was used, the retain count of foo is still greater than zero, so it will not be deallocated. Therefore, the given code sequence guarantees the existence of the object foo past the draining of the autorelease pool pool.

Submit
37. If you override a method in a subclass there is no way to invoke the method of the same name in the parent class

Explanation

When you override a method in a subclass, you can still invoke the method of the same name in the parent class by using the "super" keyword. This allows you to access and execute the parent class's implementation of the method. Therefore, the statement that there is no way to invoke the method of the same name in the parent class is false.

Submit
38. A web-based app runs the same way as a native iPhone apps

Explanation

A web-based app does not run the same way as a native iPhone app. Native iPhone apps are specifically developed for the iOS operating system and are installed directly on the device, utilizing its full capabilities. On the other hand, web-based apps run within a web browser and are platform-independent, meaning they can be accessed from any device with a compatible browser. Therefore, the statement is false.

Submit
39. What is the value of sum after executing this loop: for (int i = 0, sum = 0;      i < 10; i += 2)    sum += i;

Explanation

The loop starts with i = 0 and sum = 0. It iterates as long as i is less than 10, incrementing i by 2 in each iteration. Inside the loop, the value of i is added to sum.

The loop will iterate 5 times, with i taking the values 0, 2, 4, 6, and 8.

The sum of these values is 20, so the value of sum after executing the loop is 20.

Submit
40. In general, a class should never own its own objects

Explanation

This statement is false because it is not a general rule that a class should never own its own objects. In object-oriented programming, it is common for a class to have ownership of its own objects. Ownership allows the class to control the lifecycle and behavior of its objects, ensuring proper initialization, cleanup, and encapsulation. Without ownership, it would be difficult to manage the relationships and dependencies between objects in a system. Therefore, it is incorrect to say that a class should never own its own objects.

Submit
41. A class can have more than one parent class.

Explanation

In object-oriented programming, a class can only have one parent class, which is known as single inheritance. This means that a class can inherit the properties and methods of only one other class. If a class needs to inherit from multiple classes, it can achieve this through interfaces or by using multiple inheritance, which is not supported in all programming languages. Therefore, the statement that a class can have more than one parent class is false.

Submit
42. What is wrong with this code? int i, j, sum; i = 100; sum = i + j;

Explanation

The code is incorrect because the variable j is not initialized before it is used in the expression "sum = i + j". In order to perform addition, both variables i and j need to have a value assigned to them.

Submit
43. A leading + sign at the start of a method indicates

Explanation

A leading + sign at the start of a method indicates that it is a class method. Class methods are associated with the class itself rather than with instances of the class. They can be called directly on the class without the need for an instance. Class methods are often used to perform operations that are related to the class as a whole rather than to specific instances.

Submit
44. Which is an example of an invalid variable name?

Explanation

The variable name "x123$" is an example of an invalid variable name because it starts with a number, which is not allowed in most programming languages. Variable names should typically start with a letter or an underscore.

Submit
45. Given the following method declaration in the interface section, what can you say about area? -(Rectangle *) area;

Explanation

The given method declaration in the interface section indicates that the "area" method takes no arguments, as there are no parameters specified in the declaration. It also states that the method returns a "Rectangle" object, as the return type is specified as "Rectangle *". Lastly, it suggests that a corresponding method definition should appear in the implementation section, as the declaration in the interface section is typically followed by its implementation in the implementation section. Therefore, all of the given statements are correct.

Submit
46. Sending an autorelease message to an object has the effect of increasing the object's retain count by 1.

Explanation

Sending an autorelease message to an object does not increase its retain count. In fact, it has the opposite effect. When an object is sent an autorelease message, it is added to the current autorelease pool. At the end of the autorelease pool's scope, the pool sends a release message to each object in the pool, effectively decreasing their retain count by 1. Therefore, sending an autorelease message does not increase the object's retain count.

Submit
47. The removeObject: method

Explanation

The removeObject: method can be used on mutable arrays, as well as on mutable sets. It allows the user to supply an isEqual: method to test for equality. Therefore, the correct answer is "All of the above".

Submit
48. What is the output from this code? int i, x = 0; for (i=5; i>0; --i)    x -= i; NSLog (@"%i", x);

Explanation

The code initializes two variables, i and x, with i being initially set to 5 and x set to 0. It then enters a for loop that decrements i by 1 each iteration until i is no longer greater than 0. Inside the loop, x is subtracted by the current value of i.

The loop will run for 5 iterations, decrementing i by 1 each time. Therefore, x will be subtracted by 5, then 4, then 3, then 2, and finally 1.

So the final value of x will be 0 - 5 - 4 - 3 - 2 - 1 = -15.

Therefore, the output from this code will be -15.

Submit
49. The line id <Painting> myObject;

Explanation

The line "id myObject;" suggests that myObject conforms to the Painting protocol. In Objective-C, the "" syntax is used to indicate protocol conformance. Therefore, this line of code is stating that myObject is an object that conforms to the Painting protocol.

Submit
50. Sending an autorelease message to an object has the effect of increasing the object's retain count by 1.

Explanation

Sending an autorelease message to an object does not increase its retain count by 1. Instead, it adds the object to the autorelease pool, which is a mechanism used in memory management in Objective-C. When the autorelease pool is drained, the object's retain count is decreased by 1. Therefore, the statement is false.

Submit
51. If you divide a float by an int the operation is done as an integer division.

Explanation

When dividing a float by an int, the operation is not done as an integer division. Instead, it is done as a floating-point division, which means that the result will be a float value. In integer division, the result would be truncated to the nearest whole number. Therefore, the correct answer is False.

Submit
52. The sequence #ifndef MIN #define MIN(x,y) ((x)<(y) \    ? (x) : (y)) #endif

Explanation

The given code snippet is a preprocessor directive that defines a macro MIN only if it is not previously defined. This means that if the macro MIN has already been defined in the code before this snippet, the code will not redefine it. If MIN is not previously defined, the code will define it using the provided implementation.

Submit
53. The statement if ( x < 10 && x > 50)    y = 100; else    y = 50;

Explanation

The given statement uses the logical operator "&&" which represents the logical AND. In this case, the condition "x 50" can never be true because it is impossible for a number to be both less than 10 and greater than 50 at the same time. Therefore, the else statement will always be executed, assigning the value 50 to y.

Submit
54. The following: #define kStudents 50

Explanation

The given code snippet uses the #define preprocessor directive to create a constant identifier called kStudents and associates it with the value 50. This means that wherever the identifier kStudents is used in the code, it will be replaced with the value 50 during the preprocessing stage. Therefore, the correct answer is "defines an identifier kStudents with associated text 50".

Submit
55. Given i = 15, what is the value of this expression: i / 2.0

Explanation

When dividing an integer by a floating-point number, the result will be a floating-point number. In this case, the expression i / 2.0 is dividing the integer 15 by the floating-point number 2.0. The result of this division is 7.5, which is a floating-point value. Therefore, the correct answer is "the floating value 7.5".

Submit
56. If x is an integer, the expression ! x

Explanation

The expression "! x" represents the logical negation of x. If x is non-zero, the logical negation of a non-zero value is 0. If x is zero, the logical negation of zero is 1. Therefore, the expression has the value 0 if x is non-zero and has the value 1 if x is zero. Thus, the correct answer is "All of the above" because all three statements are true.

Submit
57. What is wrong with this line of code? Int Sum;

Explanation

The given correct answer suggests that the issue with the line of code "Int Sum;" is related to the data type. However, without further context, it is not possible to determine the exact problem with the code. It could be that "Int" is not a valid data type in the programming language being used, or it could be a typo and should be "int" instead.

Submit
58. If I write this statement NSNumber *f =    [NSNumber numberWithFloat: 100.0]; which message expression retrieves the value?

Explanation

The correct answer is [f floatValue]. In the given code, the message expression [f floatValue] is used to retrieve the value of the NSNumber object 'f' as a float. This method returns the float value of the NSNumber object.

Submit
59. What is the value of s after executing this loop: int i = 0, s = 0; while (i < 5)    s += ++i;

Explanation

The loop starts with i and s both initialized to 0. In each iteration of the loop, i is incremented by 1 using the pre-increment operator (++i) and then added to s. This process continues until i becomes equal to 5. So, the loop will run 5 times and in each iteration, i will have the values 1, 2, 3, 4, and 5. The value of s will be updated as follows: s = 0 + 1, s = 1 + 2, s = 3 + 3, s = 6 + 4, s = 10 + 5. Therefore, the final value of s after executing the loop will be 15.

Submit
60. Given int a = 10, b = 20, c; b *= a + 5; What is the resulting value of b?

Explanation

The expression "b *= a + 5" is equivalent to "b = b * (a + 5)". So, first, the value of "a + 5" is calculated, which is 10 + 5 = 15. Then, the value of "b * (a + 5)" is calculated, which is 20 * 15 = 300. Therefore, the resulting value of b is 300.

Submit
61. All of the methods in a category must be implemented

Explanation

In object-oriented programming, a category is a way to group related methods together. However, it is not necessary for all methods in a category to be implemented. Categories allow for the organization and grouping of methods, but the implementation of individual methods within a category is optional. Therefore, the statement that all of the methods in a category must be implemented is false.

Submit
62. If you write this outside of any method or function: int gRecordCount;

Explanation

The given code snippet declares a global variable called "gRecordCount". A global variable can be accessed from other files by using an external declaration, making it accessible throughout the program. Additionally, since the variable is declared outside of any method or function, it is considered a global variable. Lastly, if no initial value is assigned to the variable, it will have a default initial value of 0. Therefore, all of the given options are correct.

Submit
63. In general, when you use the removeObjectAtIndex: method to remove an object from an array, the object's retain count will remain unchanged.

Explanation

When you use the removeObjectAtIndex: method to remove an object from an array, the object's retain count will decrease by 1. This is because removeObjectAtIndex: not only removes the object from the array but also releases its ownership. Therefore, the correct answer is False.

Submit
64. A dealloc method should

Explanation

In Objective-C, when deallocating an object, it is recommended to release its instance variables first and then send a dealloc message to the superclass. This order ensures that any resources owned by the instance variables are properly released before the object itself is deallocated. By releasing the instance variables first, we prevent any potential memory leaks or dangling pointers. Sending the dealloc message to the superclass afterwards allows the superclass to clean up any resources it may have allocated for the object.

Submit
65. 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;

Explanation

The value of z is 1 because the condition x + y > 50 is true (150 > 50) and the condition x + y

Submit
66. The iPod Touch supports garbage collection

Explanation

The iPod Touch does not support garbage collection. Garbage collection is a feature in programming languages that automatically frees up memory by removing objects that are no longer needed. Since the iPod Touch runs on iOS, which is based on the Objective-C programming language, it uses manual memory management instead of garbage collection. This means that developers need to manually allocate and deallocate memory in their code. Therefore, the correct answer is False.

Submit
67. If you override dealloc, you should first send a dealloc message to super before you release your instance variables.

Explanation

When overriding the dealloc method in Objective-C, it is not necessary to send a dealloc message to the super class before releasing instance variables. The dealloc method is automatically called when an object is deallocated, and it is responsible for releasing any resources that the object may have acquired during its lifetime. However, it is important to note that when overriding dealloc, it is still good practice to release any retained or owned instance variables before calling [super dealloc] to ensure proper memory management.

Submit
68. The difference between #import and #include is

Explanation

The correct answer is that the former (#import) prevents a file from being included multiple times. This is because when using #import, the preprocessor checks if the file has already been included and if so, it skips the inclusion. This ensures that the file is only included once, avoiding duplication and potential errors. On the other hand, #include does not have this built-in mechanism to prevent multiple inclusions, so it is possible to include the same file multiple times, leading to duplicate code and potential issues.

Submit
69. The following @protocol Painting -(void) fill; -(void) stroke; @optional -(void) erase; @end

Explanation

The given answer "All of the above" is correct because the given code defines a protocol named Painting. A protocol in Objective-C is used to define a set of methods that other classes can adopt and implement. In this case, the Painting protocol has two required methods, fill and stroke, which means any class adopting this protocol must implement these methods. Additionally, it has one optional method, erase, which means classes can choose to implement it or not. Therefore, all the options mentioned in the answer are valid explanations for the given code.

Submit
70. This code sequence NSString *m = @"Hello"; ... m = @"There";

Explanation

This code sequence is okay as written because the variable "m" is a mutable string, meaning it can be changed. The initial value of "m" is set to "Hello", but it is then reassigned to "There" without any issues. This code illustrates the difference between mutable and immutable strings, as mutable strings can be modified while immutable strings cannot.

Submit
71. This directive @interface Fraction (MathOps)   <NSCopying, NSCoding>

Explanation

This directive "@interface Fraction (MathOps) " specifies a set of methods that conforms to 2 protocols and starts a category definition. By using the parentheses after the interface name, it indicates that the methods declared within this category are an extension of the Fraction class. The "" part indicates that the methods in this category conform to the NSCopying and NSCoding protocols. Therefore, the correct answer is "Both of the above".

Submit
72. What is true about the local variable counter if this statement is executed inside a method? static int counter = 0;

Explanation

The given correct answer states that the value of the local variable "counter" will be set to 0 only once when the program begins execution. This means that every time the method is called, the value of "counter" will not be reset to 0. Instead, it will retain its value from previous method calls. Therefore, the correct answer suggests that the local variable "counter" will have a persistent value throughout the program's execution.

Submit
73. A category can be used to add new instance variables to a class.

Explanation

A category in programming is a way to add new methods to an existing class, not instance variables. Instance variables are defined within the class itself, while categories are used to extend the functionality of a class by adding new methods. Therefore, the statement that a category can be used to add new instance variables to a class is false.

Submit
74. Sending a release message to an object always causes the memory associated with that object to be released.

Explanation

Sending a release message to an object does not always cause the memory associated with that object to be released. In some programming languages, such as Objective-C, sending a release message decrements the retain count of an object, but it does not necessarily immediately deallocate the memory. The memory will only be released when the retain count reaches zero. Other objects may still hold references to the object, keeping the retain count above zero and preventing the memory from being released.

Submit
75. Given int i = 15; the expression (float) i / 2;

Explanation

The expression "(float) i / 2" is performing a typecast on the variable i, converting it from an integer to a float. This means that the division operation will be performed using floating point arithmetic. Since 15 divided by 2 is 7.5, the expression will produce a floating point result of 7.5.

Submit
76. Which value is not equivalent to the others?

Explanation

The value 0XE5 is not equivalent to the others because it is represented in hexadecimal format, while the rest of the values are represented in decimal format.

Submit
77. The continue causes execution to leave the current loop and to continue execution in the outer loop.

Explanation

The explanation for the given correct answer is that the statement is incorrect. The "continue" statement causes execution to leave the current iteration of the loop and continue with the next iteration, not to continue execution in the outer loop. Therefore, the correct answer is False.

Submit
78. NSInteger is

Explanation

The correct answer is "All of the above" because NSInteger is a type in Objective-C that can either be an int or a long int depending on the compiler options. It is not an object, but rather a primitive data type that represents an integer. Therefore, all three statements are true.

Submit
79. Given NSString *s = @"Testing 1 2 3"; what is value of this expression [s substringToIndex: 5]

Explanation

The expression [s substringToIndex: 5] returns a substring of the string 's' starting from index 0 up to index 4 (5 characters in total). In the given case, the original string 's' is "Testing 1 2 3", and the substring extracted would be "Testi".

Submit
80. Which line starts the definition of a class called XY whose parent class is NSObject?

Explanation

not-available-via-ai

Submit
81. Given int a = 25, b = 6, c = 10; The expression a / b * c + a % c has the value

Explanation

The expression first divides 25 by 6, which results in 4. Then it multiplies the result by 10, giving 40. Next, it calculates the remainder of dividing 25 by 10, which is 5. Finally, it adds the two previous results together, resulting in a final value of 45.

Submit
82. In order to make sure you release any instance variables you own, you should override the release method in your class.

Explanation

Overriding the release method in a class is not necessary to release instance variables. The release method is used in Objective-C to release memory allocated by an object, but in modern programming languages like Swift, memory management is handled automatically using ARC (Automatic Reference Counting). Therefore, there is no need to override the release method in Swift or other languages that use automatic memory management.

Submit
83. Int, float, and char are reserved words and examples of Objective-C basic objects.

Explanation

The given statement is false because int, float, and char are not reserved words in Objective-C. They are actually data types used to define variables in the Objective-C programming language. Reserved words in Objective-C are keywords that have special meanings and cannot be used as variable names or identifiers. Examples of reserved words in Objective-C include if, else, for, while, and return.

Submit
84. Can you send a message to self from inside main?

Explanation

In most programming languages, including Java, it is not possible to send a message to oneself from inside the main method. The main method is the entry point of the program and is executed only once when the program starts. It is not designed to send messages or communicate with itself. Therefore, the correct answer is False.

Submit
85. In order to make sure that an object is not inadvertently released someplace else, you

Explanation

Retaining an object ensures that its reference count is increased, preventing it from being deallocated prematurely. By retaining an object, you indicate that you want to keep using it and that it should not be released until you explicitly release it. This is important to avoid accessing deallocated memory and potential crashes in your program. Therefore, retaining an object is necessary to ensure its availability and prevent accidental release elsewhere in the code.

Submit
86. If x and y are integers, the statement if ( x = 5 )     y = 0; else    y = 1;

Explanation

The statement "if (x = 5)" is a conditional statement that checks if the value of x is equal to 5. Since the single equal sign (=) is used instead of the double equal sign (==), it is assigning the value 5 to x. Therefore, the condition will always evaluate to true and the code block "y = 0;" will be executed, resulting in the value 0 being assigned to y.

Submit
87. The difference between enclosing a file name in <...> and "..." when using #import is by default

Explanation

When using #import, enclosing a file name in <...> means that the compiler will search for the file in the system's standard include directories first, before searching the current source directory. On the other hand, enclosing the file name in "..." means that the compiler will search for the file in the current source directory first, before searching the standard include directories. Therefore, the correct answer is that the former (enclosing the file name in <...>) does not search the current source directory first.

Submit
88. Once you create a number object, you can't change its value

Explanation

The statement is true because once a number object is created, its value cannot be changed. In programming, number objects are typically immutable, meaning that their values cannot be modified after they are created. This is different from variables, which can be reassigned to different values. Therefore, if you create a number object with a certain value, you cannot change that value later on.

Submit
89. Sending a release message to an object always causes the memory associated with that object to be released.

Explanation

Sending a release message to an object does not always cause the memory associated with that object to be released. It depends on the memory management system being used. In some systems, releasing an object simply decrements its reference count, and the memory is only released when the reference count reaches zero. In other systems, releasing an object may not immediately release the memory, but instead mark it as available for reuse in the future. Therefore, it is not always guaranteed that sending a release message will immediately release the memory associated with an object.

Submit
90. If you create a new NSString object with the stringWithString: method, you can assume

Explanation

When creating a new NSString object with the stringWithString: method, the newly-created string is assumed to have been autoreleased. This means that the memory management of the string is handled automatically by the autorelease pool, and it will be released at some point in the future when the pool is drained. This allows the programmer to not worry about manually releasing the string and reduces the chances of memory leaks.

Submit
91. What can you say about the indicated statement? Fraction *f =   [[Fraction alloc] init], *g;   ... g = f; [g release]; <==  ...

Explanation

not-available-via-ai

Submit
92. What will be the value of y? #define PLUS1(x) x + 1 ... int x = 5, y = 10; ... y = PLUS1(x) * 2;

Explanation

The value of y will be 7. The macro PLUS1 is defined as x + 1. So when the expression PLUS1(x) * 2 is evaluated, it becomes x + 1 * 2. Since multiplication has higher precedence than addition, x + 1 is multiplied by 2 first, resulting in 6. Therefore, the value of y is 6.

Submit
93. Given int i = 15; the expression (float) (i / 2);

Explanation



The variable i is an integer with the value 15.

However, there's a potential issue with integer division here. When you divide two integers, the result is also an integer, which means any fractional part is truncated.

So, i / 2 will result in 15 / 2 = 7 (integer division truncates the decimal part).

Then, (float) casts this integer result to a float.

So, (float) (i / 2) will result in 7.0 as a float.
Submit
94. If you want to return an object back to the caller of your method and you want to mark the object for later release, you should

Explanation

When you want to return an object back to the caller of your method and mark it for later release, you should autorelease it before returning. Autoreleasing an object means that it will be added to the autorelease pool, which will release the object at a later time. This allows the caller of the method to use the object without worrying about memory management. By autoreleasing the object, you ensure that it will be released when it is no longer needed, preventing memory leaks.

Submit
95. Given that i = 11, what is the value of the expression i % 2.0

Explanation

not-available-via-ai

Submit
96. When you drain an autorelease pool all objects that have been sent autorelease messages will get deallocated

Explanation

When you drain an autorelease pool, the objects that have been sent autorelease messages will not get deallocated immediately. Instead, they will be added to the pool and will be deallocated at a later time, typically when the pool is drained again or when the pool itself is deallocated. Therefore, the statement is false.

Submit
97. If width is an instance variable, then this line in the interface section   @property int width; and this in the implementation section   @synthesize width; will

Explanation

The line "@property int width;" in the interface section declares a property called "width" with the data type of int. The line "@synthesize width;" in the implementation section generates a default getter method for the "width" property. Therefore, the correct answer is that it will generate a getter method called "width".

Submit
98. A local variable that has no default initial value and does not retain its value through method calls is

Explanation

An auto variable is a local variable that does not have a default initial value and does not retain its value through method calls. Unlike global and static variables, which have a longer lifespan and retain their values, auto variables are created and destroyed each time the method in which they are declared is called. Therefore, the correct answer is an auto variable.

Submit
99. When you drain an autorelease pool all objects that have been sent autorelease messages will get deallocated

Explanation

When you drain an autorelease pool, only the objects that have been sent autorelease messages will have their retain count decreased by 1. However, they will not necessarily get deallocated immediately. The objects will be deallocated only when the retain count reaches 0. Therefore, the statement is false.

Submit
100. If you want to return an object back to the caller of your method and you want to mark the object for later release, you should

Explanation

When returning an object back to the caller of a method and wanting to mark it for later release, the correct approach is to copy it before returning. This ensures that the caller receives a new instance of the object, independent of the original one, and takes ownership of it. By creating a copy, any modifications made to the returned object by the caller will not affect the original object, and both can be released separately when appropriate.

Submit
View My Results

Quiz Review Timeline (Updated): Feb 9, 2024 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 09, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 12, 2012
    Quiz Created by
    Indianou
Cancel
  • All
    All (100)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
The primary root object for the Foundation framework is called...
Given an object with an instance variable called numerator and...
The id data type can be used for any object type; it is a generic...
When the retain count on an object reaches 0, the object gets sent a...
A respondsToSelector: message can be sent to an object to see if it...
You own an object that you copy
The conformsToProtocol: method can be used to see if an object belongs...
You can add more than one category to a class.
In general, you are responsible for releasing an object created with...
In general, when you add an object to a Foundation array, its retain...
In general, when you add an object to a Foundation array, its retain...
In the general form of the for statement...
The @private directive restricts access to instance variables to...
When you use alloc to create a new object, you should release the...
What file name extension is used for Objective-C code?
A newly allocated object should always be initialized
A class gets sent an initialize message when the class gets referenced...
An instance of a class is known as
The following: @interface Fraction (MathOps)   ... @end
What is wrong with this sequence of code? sum = 100; int sum;
It's okay to override init, but not considered wise to override...
In general, you are responsible for releasing an object created with...
The method names print and print: refer to two different methods.
The dealloc method is automatically called when an object's memory...
Web-based apps require users to connect to the website that host the...
If s is an NSString object, the expression [s length] - 1
If you omit a break statement at the end of a case in a switch...
A static variable will retain its value from one method call to the...
What is the value assigned to m?...
The first character in a string has an index number of 1
The main difference between NSString and NSMutableString objects is
A class definition does not contain
If x is an integer, the expression...
What is the value of sum after executing this loop:...
Data encapsulation means
In general, this sequence...
If you override a method in a subclass there is no way to invoke the...
A web-based app runs the same way as a native iPhone apps
What is the value of sum after executing this loop:...
In general, a class should never own its own objects
A class can have more than one parent class.
What is wrong with this code? int i, j, sum; i = 100; sum = i + j;
A leading + sign at the start of a method indicates
Which is an example of an invalid variable name?
Given the following method declaration in the interface section, what...
Sending an autorelease message to an object has the effect of...
The removeObject: method
What is the output from this code?...
The line id <Painting> myObject;
Sending an autorelease message to an object has the effect of...
If you divide a float by an int the operation is done as an integer...
The sequence...
The statement...
The following: #define kStudents 50
Given i = 15, what is the value of this expression: i / 2.0
If x is an integer, the expression ! x
What is wrong with this line of code? Int Sum;
If I write this statement...
What is the value of s after executing this loop:...
Given...
All of the methods in a category must be implemented
If you write this outside of any method or function:...
In general, when you use the removeObjectAtIndex: method to remove an...
A dealloc method should
What is the value of z after executing this sequence (check...
The iPod Touch supports garbage collection
If you override dealloc, you should first send a dealloc message to...
The difference between #import and #include is
The following...
This code sequence...
This directive...
What is true about the local variable counter if this statement is...
A category can be used to add new instance variables to a class.
Sending a release message to an object always causes the memory...
Given int i = 15; the expression (float) i / 2;
Which value is not equivalent to the others?
The continue causes execution to leave the current loop and to...
NSInteger is
Given...
Which line starts the definition of a class called XY whose parent...
Given...
In order to make sure you release any instance variables you own, you...
Int, float, and char are reserved words and examples of Objective-C...
Can you send a message to self from inside main?
In order to make sure that an object is not inadvertently released...
If x and y are integers, the statement...
The difference between enclosing a file name in <...> and...
Once you create a number object, you can't change its value
Sending a release message to an object always causes the memory...
If you create a new NSString object with the stringWithString: method,...
What can you say about the indicated statement?...
What will be the value of y?...
Given int i = 15; the expression (float) (i / 2);
If you want to return an object back to the caller of your method and...
Given that i = 11, what is the value of the expression i % 2.0
When you drain an autorelease pool all objects that have been sent...
If width is an instance variable, then this line in the interface...
A local variable that has no default initial value and does not retain...
When you drain an autorelease pool all objects that have been sent...
If you want to return an object back to the caller of your method and...
Alert!

Advertisement