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

Multiple choice
  1. It is used to add functionality to the existing class without inheriting that class.

  2. It is mandatory to have the implementation of the code to specify category in the class.

  3. @interface ClassName (CategoryName) @end is the correct syntax to declare a category.

  4. The methods in a category have access to all instances of the class and also the subclass.

  5. A category is usually declared in a separate header file and implemented in a separate source code file.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A category can be declared for any class, even if one does not  have the original implementation source code.

Multiple choice
  1. It is mandatory to have the source code at compile time to specify extension in the class.

  2. The methods declared by a class extension are implemented in the @implementation block for the original class.

  3. @interface ClassName () @end is the syntax for extension.

  4. A class extension can not add its own properties and instance variables to a class.

  5. Class extensions are called “anonymous” categories.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In contrast to categories, a class extension can add own properties and instance variable to a class.

Multiple choice
  1. By default all instance variables and local variables are strong pointers.

  2. A weak reference is a reference that one does not retain.

  3. A weak attribute reference is not proper for the protection of the reference object.

  4. The attribute 'assign' is a property attribute that tells the compiler how to synthesise the property's setter implementation.

  5. None of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

All are correct statements.

Multiple choice
  1. It is used to replace an existing class in a program.

  2. A class may only pose as one of its direct or indirect superclasses.

  3. The posing class must not define any new instance variables that are absent from the target class.

  4. A posing class can call overridden methods through super, thus incorporating the implementation of the target class.

  5. A posing class can not override methods defined in categories.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is incorrect as the posing class can override methods defined in categories.

Multiple choice
  1. It is used to get the current set of coded classes that allow secure coding.

  2. It returns a Boolean value that indicates whether the receiver supports keyed coding of objects.

  3. It returns a Boolean value that indicates whether an encoded value is available for a string.

  4. It encodes a buffer of data whose types are unspecified.

  5. None of the these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is true about allowedClasses method.

Multiple choice
  1. It an abstractClass which represents a stream of data.

  2. This class provides the basis for archiving.

  3. NSCoder objects are usually used in a method that is being implemented so that the class conforms to the protocol.

  4. It can operate on different data types and reference types.

  5. All of these

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Yes, all are correct.

Multiple choice
  1. This class declares the programmatic interface to objects that manage a modifiable array of objects.

  2. NSMutableArray is a subclass of NSArray.

  3. This class is used when one is sure that the data, which will be storing inside the NSArray, will be static and not dynamic.

  4. The array cannot be changed after initialised.

  5. NSMutableArray is used for like a UITableView data source.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, it is the correct answer. The array can be changed anytime after initialisation.

Multiple choice
  1. The constructors are declared with the prefix init.

  2. The constructors are inherited from NSObject class.

  3. -(id)initWithName:(NSString *) aName; is a correct declaration of constructor.

  4. id means that our method will be returning a value that is not yet defined.

  5. None of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

All are the correct statements.