0% found this document useful (0 votes)
6 views

Important 2

Uploaded by

engysaad573new
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Important 2

Uploaded by

engysaad573new
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Time: 30 Min.

Course: Objective C

MCQ True/False

1- 1-

2- 2-

3- 3-

4- 4-

5- 5-

6- 6-

7- 7-

8- 8-

9- 9-
#import <Cocoa/Cocoa.h> #import <Foundation/Foundation.h>
# import "ClassA.h" @interface ClassA : NSObject{
int x;
int main(int argc, const char * }
argv[]) { -(void) methodA;
ClassA *obj = [ClassA new]; @end
[obj methodA];
@implementation ClassA
return 0; -(void) methodA{
} printf("this is method A\n");
Main.m }
@end
1- The above code: classA.h
A- Will print -> this is method A.
B- Generate compile time error both interface and implementation in one file.
C- Generate run time error as both interface and implementation in one file.
#import <Foundation/Foundation.h>
#import "Person.h"
@interface Person : NSObject #import "ClassA.h"

@end @implementation Person: ClassA

@end
2- The above code:
A- Will compile and run correctly.
B- Generate Compile time error “Conflicting super class name ‘ClassA’ ”.
C- Generate Run time error because the parent class in the implementation file is different.

#import "Person.h"
int main(int argc, const char *
#import <Foundation/Foundation.h>
argv[]) {
@interface Person : NSObject{
Person *p = [Person new];
int num;
p->num = 5;
}
@end
return 0;
}
3- The above code:
A- Will compile and run correctly.
B- Generate Compile time error.
C- Generate Run time error.

#import "Person.h"
int main(int argc, const char * #import <Foundation/Foundation.h>
argv[]) {
@interface Person : NSObject{
Person *p = [Person new]; @property int idNum;
p.idNum = 10; }

return 0; @end
}
4- The above code:
A- Will compile and run correctly.
B- Generate Compile time error “Unknown type name ‘property’”.
C- Generate Run time error.

5- In Inheritance, New methods added to the child are able to use:


A- The parent(s) protected and public variables.
B- Both class/instance methods of the parent.
C- All the above.

NSString* var1 = [[NSString alloc] initWithString:@"hello"];


NSString* var2 = [someOtherString copy];
NSString* var3 = [NSString new];

[var1 release];
[var2 release];
[var3 release];

6- The above code …


A. Has no problems, each object has its own RC and will be zeros at the end.
B. Var1 has a problem, sense it points to the same RC of object @”hello”, and we
must call retain method to increase the RC.
C. Var2 has a problem, sense it points to the same RC of var 1, and we must call retain
method to increase the RC.
D. Must not call release method, we should call dealloc instead.
7- (ClassA+Multiplication) -> this name mostly for :
A. Protocol file
B. Protocol name
C. Category name
D. Category file
8- If I call alloc without init what will happen??
A. Compile time error
B. Linker command error
C. Run time error
D. It will run normally but it may cause errors in some situations.
9- Consider that myPro is a property:

int x = self.myPro;

// the above line equivalent to the below line:


int x = [self getMyPro] // this is generated metho
d
A. True
B- False
State if the following statements are true or false :

1- Objective C is Structured programming Language. ( false )


2- isMemberOfClass: returns YES if the receiver is an instance/descent of the specified class.( false )
3- The name of a method declared in a category should not be the same as a method in the
original class. ( true )
4- Methods that are defined in protocol without adding (required, optional) are optional by
default. ( false )
5- We must enable the ARC to be able to send retain and release messages. ( false )
6- Every object in Objective-C uses reference counting to manage its lifecycle, even if we used ARC!
( true )
7- We can declare properties in the .m file, but it will be private by default. ( false )
8- If we defined Static Keyword in the implementation section inside the @ implementation
directive outside the curly braces{}, it will be visible only in the implementation file so it needs
setter and getter methods. ( true )
9- [new] message in Objective C sends [init] message and returns the initialized object. ( true )

Best Luck.

You might also like