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
-
declare a member function that is defined in a subclass
-
designate the absence of a type
-
declare objects that can be modified outside of program control
-
declare a synonym for an existing type
B
Correct answer
Explanation
The 'void' keyword is used to indicate that a function does not return a value or that a pointer is generic (void pointer). It signifies the absence of a specific type.
-
avoid arguments between classes
-
allow access to classes whose source code is unavailable
-
allow one class to access an unrelated class
-
increase the versatility of an member function
C
Correct answer
Explanation
A friend function is a function that is not a member of a class but is granted access to the private and protected members of that class. This allows it to interact with the class data without being part of the class interface.
-
Access File class
-
Random Access File class
-
Data in out stream
-
None of these
-
Stream
-
Package
-
Class
-
None of these
A
Correct answer
Explanation
In Java I/O, a 'Stream' is the abstraction used for a sequence of data that can be produced (output) or consumed (input).
-
compile time entities
-
runtime entities
-
both (1) and (2)
-
none of these
B
Correct answer
Explanation
In object-oriented programming, objects are instances of classes that exist during the execution of the program (runtime).
B
Correct answer
Explanation
C++ supports operator overloading, whereas Java does not support it to maintain simplicity.
-
The package definition must come first
-
Class should be private
-
Method should be without void
-
None of these
A
Correct answer
Explanation
Java source files follow a strict ordering rule where the package statement must be the first non-comment line. In the provided code, import statements appear before the package declaration, which will cause a compiler error. To fix this, the package student; line must be moved to the top of the file.
A
Correct answer
Explanation
Java's class structure, which groups data fields together, is conceptually similar to the struct type found in the C programming language.
-
class
-
object
-
method
-
signature
A
Correct answer
Explanation
A class acts as a template or blueprint that defines the properties and behaviors that all objects of that type will possess.
-
signature
-
class
-
method
-
inheritance
A
Correct answer
Explanation
A method signature consists of the method name and the parameter list (types and order), which uniquely identifies the method within a class.
-
An instance
-
An abstract
-
A class
-
None of the above
B
Correct answer
Explanation
An abstract method is declared without an implementation body; it must be implemented by non-abstract subclasses.
A
Correct answer
Explanation
In Java, all non-static methods are virtual by default, meaning they can be overridden by subclasses.
-
An instance
-
An abstract
-
A class
-
None of the above
B
Correct answer
Explanation
An abstract class is a class that cannot be instantiated and is intended to be subclassed, with abstract methods providing the 'gaps' for subclasses to fill.
-
super
-
final
-
root
-
none of the above
B
Correct answer
Explanation
The 'final' keyword prevents a class from being extended (subclassed) and prevents methods from being overridden.
-
assigned the reference to a value
-
invoked a method on the reference
-
extracted a field from the reference
-
casted the reference to another