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
-
Integer
-
Character
-
Boolean
-
None of these
B
Correct answer
Explanation
Character class does not take string as argument (refer API).
-
It is an operator.
-
It is a keyword.
-
It is an interface.
-
None of these
A
Correct answer
Explanation
'instanceof' is an operator, which is used to know the type of an object during runtime.
-
this
-
super
-
both (1) and (2)
-
none of these
C
Correct answer
Explanation
'this' is used for calling same class constructor, and 'super' is used for calling parent class constructor. So, this is the most appropriate answer.
-
public and non-static
-
default and abstract
-
private and static
-
public and abstract
D
Correct answer
Explanation
This option is true because methods, which are declared in inteface are by default public and abstract.
-
Default
-
Public
-
Protected
-
Private
C
Correct answer
Explanation
Return type of finalize() method is protected and this method is called by the garbage collector on an object, when garbage collection determines that there are no more references to the object.
-
Public
-
Private
-
Default
-
Protected
C
Correct answer
Explanation
Default is known as package accessible modifier because it is accessible in the same package where it is declared.
-
as soon as class gets loaded
-
by explicitly
-
when object is created
-
none of these
C
Correct answer
Explanation
When we create reference/object of any class, which is accessible, then non static block is called.
B
Correct answer
Explanation
This is the correct answer. There are 7 subclasses of the InputStream class.
These are:
- FileInputStream for reading bytes from a file.
- ObjectInputStream for readin objects and primitive data types from input stream.
- SequenceInputStream for readin from a sequence of streams.
- ByteArrayInputStream for Stream that reads a byte array.
- pipedInputStream for reading from a piped stream.
- FilterInputStream for filtering input from Existing Stream.
- StringBufferInputStream for reading from a string.
C
Correct answer
Explanation
There five subclasses of the OutputStream class are:
- FileOutputStream for writing bytes into file
- ObjectOutputStream for writing objects and primitive data types to output stream.
- ByteArrayOutputStream for output stream that writes byte into array.
- pipedOutputStream for writing into a piped stream.
- FilterOutputStream for filtering output into an existing stream.
So, this is the correct answer.
D
Correct answer
Explanation
This is the correct answer. Byte stream can be defined by using two class hierarchies.
These two classes are :
- InputStream
- OutputStream
C
Correct answer
Explanation
This is the correct answer. Character stream class is defined by using two class hierarchies.
These classes are:
- Reader class
- Writer class.
-
ObjectOutputStream
-
PipedOutputStream
-
ByteOutputStream
-
Both (1) and (2)
-
All of the above
D
Correct answer
Explanation
As explained, both options 1 and 2 are correct. So, this is the correct choice.
D
Correct answer
Explanation
There are 6 subclasses of reader Class in Java. These are:
- BufferedReader for buffering other readers
- ChararrayReader for reading from char array
- FilterReader for reading filter streams
- InputStreamReader for reading a character stream
- PipedReader for reading from pipe
- StringReader for reading from a string
So, this is the correct answer.
A
Correct answer
Explanation
There are 7 subclasses of the Writer class in Java.
These are:
- OutputStreamWrite for writing a character stream
- BufferedWriter for buffering other writers
- PrintWriter for writing formatted data
- PipedWriter for writing to a pipe
- CharArrayWriter for writing to a char array
- StringWriter for writing to a string
- FilterWriter for writing filtered streams.
So, this is the correct answer.
-
ProtectedMemory
-
SHA1CryptoServiceProvider
-
SHA256CryptoServiceProvider
-
SHA384
-
SHA384CryptoServiceProvider
E
Correct answer
Explanation
This .NET cryptographic class defines a wrapper object to access the CSP implementation of the SHA384 algorithm.