Computer Knowledge
Object-Oriented Programming
2,686 Questions
Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.
Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects
Object-Oriented Programming Questions
-
Factory class
-
Meta class
-
Final class
-
_destructor()
-
RemoteStackVariable class
A
Correct answer
Explanation
This class receives some input and according to that input, it decides what class instance is to be created.
-
It is used to add functionality to the existing class without inheriting that class.
-
It is mandatory to have the implementation of the code to specify category in the class.
-
@interface ClassName (CategoryName) @end is the correct syntax to declare a category.
-
The methods in a category have access to all instances of the class and also the subclass.
-
A category is usually declared in a separate header file and implemented in a separate source code file.
B
Correct answer
Explanation
A category can be declared for any class, even if one does not have the original implementation source code.
-
It is mandatory to have the source code at compile time to specify extension in the class.
-
The methods declared by a class extension are implemented in the @implementation block for the original class.
-
@interface ClassName () @end is the syntax for extension.
-
A class extension can not add its own properties and instance variables to a class.
-
Class extensions are called “anonymous” categories.
D
Correct answer
Explanation
In contrast to categories, a class extension can add own properties and instance variable to a class.
-
By default all instance variables and local variables are strong pointers.
-
A weak reference is a reference that one does not retain.
-
A weak attribute reference is not proper for the protection of the reference object.
-
The attribute 'assign' is a property attribute that tells the compiler how to synthesise the property's setter implementation.
-
None of the above
E
Correct answer
Explanation
All are correct statements.
-
It is used to replace an existing class in a program.
-
A class may only pose as one of its direct or indirect superclasses.
-
The posing class must not define any new instance variables that are absent from the target class.
-
A posing class can call overridden methods through super, thus incorporating the implementation of the target class.
-
A posing class can not override methods defined in categories.
E
Correct answer
Explanation
This is incorrect as the posing class can override methods defined in categories.
-
It is used to get the current set of coded classes that allow secure coding.
-
It returns a Boolean value that indicates whether the receiver supports keyed coding of objects.
-
It returns a Boolean value that indicates whether an encoded value is available for a string.
-
It encodes a buffer of data whose types are unspecified.
-
None of the these
A
Correct answer
Explanation
This is true about allowedClasses method.
-
It an abstractClass which represents a stream of data.
-
This class provides the basis for archiving.
-
NSCoder objects are usually used in a method that is being implemented so that the class conforms to the protocol.
-
It can operate on different data types and reference types.
-
All of these
-
This class declares the programmatic interface to objects that manage a modifiable array of objects.
-
NSMutableArray is a subclass of NSArray.
-
This class is used when one is sure that the data, which will be storing inside the NSArray, will be static and not dynamic.
-
The array cannot be changed after initialised.
-
NSMutableArray is used for like a UITableView data source.
D
Correct answer
Explanation
Yes, it is the correct answer. The array can be changed anytime after initialisation.
-
- (id)initWithBool:(BOOL)value;
-
- (id)initWithFloat:(float)value;
-
- (id)initWithInt:(int)value;
-
- (id)initWithLong:(long)value;
-
All of these
-
The constructors are declared with the prefix init.
-
The constructors are inherited from NSObject class.
-
-(id)initWithName:(NSString *) aName; is a correct declaration of constructor.
-
id means that our method will be returning a value that is not yet defined.
-
None of the above
E
Correct answer
Explanation
All are the correct statements.
-
Anonymous type
-
Built-in numeric type
-
Value type
-
Static modifier
-
FTP service
A
Correct answer
Explanation
This type of data type consists of a set of public properties encapsulated in a nameless reference type.
-
Internal
-
Static modifier
-
Reference types
-
Value types
-
Built-in types
C
Correct answer
Explanation
These data types include classes, interfaces, arrays and delegates.
-
Protected
-
Delegate
-
Event
-
RemoteStackFrame class
-
Abstract class
B
Correct answer
Explanation
This class has a signature and it can hold references only to methods that match its signature.
-
Strong name information
-
Static modifier
-
Public
-
Protected
-
Internal
C
Correct answer
Explanation
By using this access modifier, access is not restricted at all.
-
generic
-
meta
-
abstract
-
RemoteStackFrame
-
ProtectedData
A
Correct answer
Explanation
The most common use for generic classes are with collections like linked lists, hash tables, stacks, etc.