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
-
It has distinct objects.
-
It is immutable.
-
It is used to store and retrieve primitive values.
-
The elements can be altered in NSSet.
-
An NSSet can be created through the set with objects: class method.
C
Correct answer
Explanation
It is not used with primitive values as it is not a wrapper class.
-
It is a lightweight class.
-
It is used to store and retrieve primitive values.
-
%@ format specifier is used for this class.
-
NSNumber objects are immutable.
-
The NSNumber object can be made mutable.
E
Correct answer
Explanation
These objects can not be made mutable.
-
These are used to declare the data of a class.
-
The most commonly used parameters are copy/retain/assign in the Property.
-
The assign keyword generates a setter, which do not have retained objects.
-
The assign can be interchanged with another object's property.
-
The read-only keyword is used to generate the setters.
E
Correct answer
Explanation
The read-only keyword means a setter will not be generated.
-
It is used to implement the code for the accessors.
-
Synthesised accessors are atomic.
-
Synthesised accessors can not be nonatomic.
-
The getters must have a value as per the setters.
-
There is no cost for the synthesised property if garbage collection is enabled.
C
Correct answer
Explanation
One can disable the synthesised property with the keyword nonatomic.
-
These are used to declare methods for others to implement.
-
These are used to declare the interfaces to a particular class.
-
Protocols establish the common attributes among the classes in different hierarchy.
-
Protocols manage the execution state of the application.
-
Protocols play an important role in OS X and iOS development.
D
Correct answer
Explanation
Protocols do not manage the execution state for the application and these are used to declare the application's functionality.
-
These are used to maintain a common abstract superclass for all the subclasses.
-
These provide the specific values based on the inputs for all the subclasses.
-
The abstract class for the Cluster can not be defined with the composite object.
-
Bool is a Cluster class of NSNumber.
-
It uses the functionality like abstract factory.
C
Correct answer
Explanation
The composite object must declare itself to be a subclass of the cluster's abstract superclass.
-
It acts as a medium between the memory system and the garbage collection.
-
All the released objects are included in the autorelease pool.
-
All of the objects must be passed in a method pool.
-
Some objects can be forced to autorelease.
-
Every program must create its own object.
D
Correct answer
Explanation
The objects cannot be forced to autorelease.
-
A category can be declared for any class in the source code.
-
It cannot be declared for any class, only for the classes that have original implementation of source code.
-
All the methods in a category should be applicable to all the instances of the class.
-
All the methods in a category should be applicable to all subclasses of the original class.
-
At runtime, there's no difference between a method added by a category with its implementation.
B
Correct answer
Explanation
A category can be declared for any class even without implemented code.
-
An Extension can be declared for any class in the source code.
-
It cannot be declared for any class in the source code.
-
Extensions are also known as anonymous categories.
-
The methods and variables declared inside the extensions are not accessible to the child classes.
-
@interface keyword is used to declare the extension.
A
Correct answer
Explanation
An extension cannot be declared for any class, only for the classes that have original implementation of source code.
-
OVERRIDING
-
FINAL
-
NOT INSTANTIABLE
-
None of these
A
Correct answer
Explanation
OVERRIDING in Oracle tells that the subtype methods will override the subtype's methods.
-
OVERRIDING
-
FINAL
-
NOT INSTANTIABLE
-
None of these
C
Correct answer
Explanation
NOT INSTANTIABLE tells Oracle that this method is not avaliable in the subtype.
-
member method
-
static method
-
constructor method
-
none of these
A
Correct answer
Explanation
Calling programs may invoke member method only on objects that have been instantiated.
-
Member methods
-
Constructor method
-
Comparison methods
-
None of these
B
Correct answer
Explanation
Even if no method is declared, every instantiable object has a default constructor method that allows a calling program to create new objects of that type.
-
Inheritance
-
Encapsulation
-
Abstraction
-
Class
-
None of these
C
Correct answer
Explanation
Abstraction refers to the act of hiding actual details from the user.
-
class classname {varibale declaration function declaration};
-
class {variables; function;};
-
class classname{variables function};
-
class classname;{ };
-
class classname {member variables; member function;}
A
Correct answer
Explanation
This is the correct syntax of declaring a class and members of the class.