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
-
private and public
-
public and private
-
private and private
-
public and public
A
Correct answer
Explanation
The protected access specifier works as private for outside world, but works as public for derived classes in Java.
-
static
-
this(parameter list)
-
this
-
static(parameter list)
B
Correct answer
Explanation
If the first statement of a constructor has the form this(parameter list), then the constructor calls another constructor of the same class. For example:
class Emp
{
int m;
double n;
public Emp(int x)
{
this(789.89,x);
}
}
Here, this(789.89,x) statement calls the constructor Emp(double,int)
-
simple
-
multiple
-
multilevel
-
hierarchical
C
Correct answer
Explanation
The protected access specifier is very useful in multilevel inheritance because the protected member of super class A can be accessed by the subclass C in the following way.
A(Super Class)$\rightarrow$ B(Subclass of A) $\rightarrow$C(Subclass of B)
-
Private
-
Generic
-
Protected
-
Synchronized
-
All of the above
B
Correct answer
Explanation
generic does not works as a modifier.
-
Only A
-
Only B
-
Both A and B
-
Neither A nor B
B
Correct answer
Explanation
It is not necessary that the static methods are always public. But it is true that static methods cannot access directly non-static method of the same class.
-
Subclass
-
Native
-
Array
-
None of theses
-
All of these
B
Correct answer
Explanation
Native is a Java keyword that is used in method declarations to specify that the method will not be implemented in another language, not in Java.
-
A final class can be extended by another class.
-
A final method can be overridden when its class is inherited.
-
A final variable's value cannot be changed.
-
The keywords final and finally have the same meaning in Java.
-
Final class can be abstract in Java.
C
Correct answer
Explanation
This is the correct answer. A final variable is equivalent to a constant. Once a value is assigned to it, it cannot be changed.
-
Method
-
Native
-
Subclasses
-
Reference
-
Array
B
Correct answer
Explanation
The word native is a valid keyword, used to modify a method declaration.
-
No
-
Yes
-
DTD's are recommendation only
-
None of these
A
Correct answer
Explanation
DTD's do not follow the inheritance principle, as they do not form any relationship. So other options are wrong.
-
Float
-
Integer
-
Double
-
String
-
Byte
D
Correct answer
Explanation
This is a correct answer. String is not a wrapper class in java.
-
classes only
-
methods only
-
data members only
-
classes, methods and data members
-
interfaces only
D
Correct answer
Explanation
This is a wrong answer. Interfaces cannot be marked as final.
This is the correct answer. Final keyword can be used with classes, methods and data members.
-
integers
-
final
-
protected
-
private
-
string
B
Correct answer
Explanation
This is the correct answer. All data members inside an interface need to be final. Once the data members are final, their values cannot be changed. If we do not make the data members final, it will result in compile time error.
-
Class A extends class B.
-
Class B is superclass of class A.
-
Class A inherits from class B.
-
Class B is subclass of class A.
-
Class A is subclass of class B.
D
Correct answer
Explanation
This is the correct answer. As class B is extending from class A, hence class A is the superclass and class B is the subclass.
-
Only A
-
Only B
-
Both A and B
-
Neither A nor B
C
Correct answer
Explanation
Both are the properties of a constructor. A constructor does not have any return type and cannot be declared as private.
-
multi-constructor
-
default Constructor
-
constructor overloading
-
constructor overriding
C
Correct answer
Explanation
If there are more than one constructor in a class, then its termed as constructor overloading.