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: 469 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. Which of the following can be inherited?

Explanation

Classes can be inherited in object-oriented programming. Inheritance allows a class to inherit properties and methods from another class, known as the superclass or parent class. This enables code reusability and promotes a hierarchical structure in the program. The child class, also known as the subclass, can inherit and extend the functionality of the parent class, adding its own unique properties and methods. Inheritance is a fundamental concept in object-oriented programming and is used to create relationships between classes, promoting code organization and modularity.

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

This Objective C & OOP Examination 2 assesses knowledge in Objective C syntax, memory management, and OOP principles. It tests skills in function pointers, NSString manipulations, memory address behaviors, array operations, type conversions, and protocol conformances, suitable for learners aiming to enhance their programming expertise.

Personalize your quiz and earn a certificate with your name on it!
2. How do you throw an exception?

Explanation

To throw an exception, the correct syntax is "@throw e". This statement is used to raise an exception and pass it to the calling code. The "@" symbol is commonly used in programming languages to indicate that something is a keyword or a special instruction. Therefore, "@throw e" is the appropriate way to throw an exception. The other options, including "@raise e", "RAISE( e )", "THROW( e )", and "None of the above", are not the correct syntax for throwing an exception.

Submit
3. What can you assume when calling the "stringWithString:" method on a "NSString" object?

Explanation

When calling the "stringWithString:" method on an "NSString" object, you can assume that the returned object is auto-released. This means that you do not need to manually release the memory used by the returned object, as it will be taken care of by the autorelease pool.

Submit
4. What class specifiers are supported by Objective-C?

Explanation

Objective-C does not have any class specifiers. In Objective-C, class declarations are done using the @interface keyword and class implementations are done using the @implementation keyword. Class specifiers are used in other programming languages to provide additional information or restrictions on classes, but Objective-C does not have any built-in class specifiers.

Submit
5. Which of the following creates a class that conforms to a protocol?

Explanation

The correct answer is "@interface ClassName ". This syntax in Objective-C is used to create a class that conforms to a protocol. The angle brackets "" are used to specify the protocol that the class is conforming to.

Submit
6. After the execution of the following code, what is the retain count of the "s1"? NSMutableString * s1; NSMutableString * s2; s1 = [ [ [ NSMutableString alloc ] initWithString: @"Hello world!" ] autorelease ]; [ [ [ [ s1 retain ] retain ] retain ] release ]; s2 = [ s1 copy ]; [ s1 release ];

Explanation

The retain count of "s1" is 2 because it is initially assigned a mutable string object with a retain count of 1. Then, it is retained three more times using the "retain" method, increasing the retain count to 4. However, it is also released once using the "release" method, decreasing the retain count to 3. Finally, "s1" is copied to "s2", which creates a new string object with a retain count of 1. After that, "s1" is released again, decreasing its retain count to 2.

Submit
7. What can you say about the memory addresses that will be printed by the following program? #import <Cocoa/Cocoa.h> int main( void ) { NSAutoreleasePool * pool; NSString * s1; NSString * s2; NSString * s3; NSString * s4; pool = [ [ NSAutoreleasePool alloc ] init ]; s1 = @"Hello world!"; s2 = @"Hello world!"; s3 = [ NSString stringWithString: @"Hello world!" ]; s4 = [ [ NSString alloc ] initWithString: @"Hello world!" ]; printf( "%p\n%p\n%p\n%p\n", s1, s2, s3, s4 ); [ s4 release ]; [ pool release ]; return 0; }

Explanation

The program initializes four different NSString variables with the same string "Hello world!". However, the memory addresses of these variables will be the same because the NSString class uses a technique called string interning. String interning allows multiple variables to point to the same memory address if they have the same string value, in order to save memory. Therefore, in this program, all the addresses will be the same.

Submit
8. What is the default visibility for instance variables?

Explanation

The default visibility for instance variables is @public. This means that instance variables can be accessed and modified by any class or method within the same package or in any subclass, regardless of the package.

Submit
9. What will be printed by the following program? #include <stdio.h> int main( void ) { unsigned int array[ 2 ][ 2 ] = { { 0, 1 }, { 2, 3 } }; unsigned int i = 0; unsigned int sum = 0; int x = 0; int y = 0; for( i = 0; i < 4; ++i ) { x = i % 2; y = ( x ) ? 0 : 1; sum += array[ x ][ y ]; } printf( "%d\n", sum ); return 0; }

Explanation

The program initializes a 2x2 array with values {0, 1, 2, 3}. It then uses a for loop to iterate through the array. The variable x is set to the remainder of i divided by 2, which will alternate between 0 and 1. The variable y is set to 0 if x is 1, and 1 if x is 0. This means that the program will access the elements in the array in the order {0, 0}, {1, 1}, {0, 0}, {1, 1}. The sum variable is incremented by the value at each accessed element. Therefore, the final sum will be 0 + 3 + 0 + 7 = 10.

Submit
10. What happen when a floating point value is assigned to an integer variable?

Explanation

When a floating point value is assigned to an integer variable, the assignment is not done as it is considered invalid. This is because floating point values contain decimal places and can have a larger range of values compared to integers, which only store whole numbers. Therefore, the conversion from a floating point value to an integer would result in a loss of precision or information, making the assignment invalid.

Submit
11. What does Objective-C not support?

Explanation

Objective-C does not support variable arguments. Variable arguments allow a function or method to accept a varying number of arguments. In Objective-C, the number and types of arguments must be explicitly defined in the method signature. Variable arguments are commonly used in languages like C and C++, but Objective-C does not provide direct support for them.

Submit
12. What is the correct syntax for declaring the prototype of a block named "foo" returning an integer and taking a character pointer as argument?

Explanation

not-available-via-ai

Submit
13. What type of variable do you need to use to implement the singleton pattern?

Explanation

The singleton pattern is implemented using a static variable. However, in this question, the correct answer is "None of the above" because none of the options listed (static, auto, const, volatile, extern) specifically refers to the type of variable needed to implement the singleton pattern.

Submit
14. Which is the correct syntax to declare a function pointer named "foo" returning an integer and having an integer as argument?

Explanation

not-available-via-ai

Submit
15. What is a category?

Explanation

A category in programming refers to a way to add additional methods to an existing class without modifying its original implementation. It allows for extending the functionality of a class without subclassing or modifying the original class. Therefore, the correct answer is "None of the above" as none of the options accurately describe what a category is.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 16, 2012
    Quiz Created by
    Indianou
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following can be inherited?
How do you throw an exception?
What can you assume when calling the "stringWithString:"...
What class specifiers are supported by Objective-C?
Which of the following creates a class that conforms to a protocol?
After the execution of the following code, what is the retain count of...
What can you say about the memory addresses that will be printed by...
What is the default visibility for instance variables?
What will be printed by the following program?...
What happen when a floating point value is assigned to an integer...
What does Objective-C not support?
What is the correct syntax for declaring the prototype of a block...
What type of variable do you need to use to implement the singleton...
Which is the correct syntax to declare a function pointer named...
What is a category?
Alert!

Advertisement