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
-
ProtectedMemory
-
Private
-
Protected
-
Internal
-
Static modifier
B
Correct answer
Explanation
By using this access modifier, access is limited to the containing type.
-
DatagramPacket class
-
Dynamic proxy class
-
Proxy class
-
Proxy instance
-
RemoteStackFrame class
B
Correct answer
Explanation
It is a class that implements a list of interfaces that is implemented by a proxy class.
-
Polymorphism
-
Inheritance
-
Message communication
-
Operator overloading
D
Correct answer
Explanation
Java does not support operator overloading to maintain simplicity and avoid the complexities found in languages like C++.
B
Correct answer
Explanation
Java passes object references by value. While you cannot change the reference itself to point to a new object outside the method, you can modify the state of the object being referenced, which is effectively call-by-reference behavior for object contents.
-
Class
-
Package
-
Interface
-
Main method
B
Correct answer
Explanation
According to Java language specifications, if a package statement is used, it must be the first non-comment statement in the source file.
A
Correct answer
Explanation
In Java, all methods defined in an interface are implicitly public. When a class implements an interface, the implementation must also be declared as public.
B
Correct answer
Explanation
Not all methods can be overridden. Methods marked as 'final' or 'static' in a superclass cannot be overridden in a subclass.
-
close
-
terminate
-
end
-
final
D
Correct answer
Explanation
Declaring a class as 'final' prevents it from being subclassed. This is a common practice to ensure the integrity of a class by preventing unwanted extensions.
-
sub-classes
-
super classes
-
extended classes
-
none of the above
-
ii & iii
-
i & ii
-
i & iv
-
iii & iv
A
Correct answer
Explanation
Statement ii is true because a final class cannot be extended, so abstract methods (which require implementation) cannot exist. Statement iii is true because inner classes can have any access modifier. Statement i is false (abstract classes can have final methods), and iv is false (transient variables do not have to be static).
-
attributes and names
-
operations and names
-
attributes, names and operations
-
none of the above
C
Correct answer
Explanation
In object-oriented design, an object is defined as an entity that encapsulates both data (attributes) and the behaviors (operations) that act upon that data, identified by a unique name.
-
a function returns by value
-
an argument is passed by value
-
a function calls to another function
-
an argument is passed by reference
A
Correct answer
Explanation
A copy constructor is invoked when an object is returned by value from a function, as a temporary object is created and copied to the caller. While passing by value also invokes a copy constructor, returning by value is a classic scenario where this occurs.
-
make general classes into more specific classes
-
pass arguments to objects of classes
-
add features to existing classes by rewriting them
-
improves data hiding and encapsulation
A
Correct answer
Explanation
Inheritance allows a new class (derived class) to acquire the properties and behaviors of an existing class (base class), effectively creating more specific versions of general classes.
-
a class
-
an operator
-
a data item
-
a member function
D
Correct answer
Explanation
A function defined inside a class is referred to as a member function. It has access to the private and protected members of the class.
-
resolved ambiguity by specifying a particular class
-
limits the visibility of variables
-
informs which base class is derived
-
ensures copying data types
A
Correct answer
Explanation
The scope resolution operator (::) is used to specify which class or namespace a member belongs to, thereby resolving ambiguity when multiple entities share the same name.