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

Multiple choice
  1. static

  2. this(parameter list)

  3. this

  4. static(parameter list)

Reveal answer Fill a bubble to check yourself
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)

Multiple choice
  1. simple

  2. multiple

  3. multilevel

  4. hierarchical

Reveal answer Fill a bubble to check yourself
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)

Multiple choice
  1. Subclass

  2. Native

  3. Array

  4. None of theses

  5. All of these

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. A final class can be extended by another class.

  2. A final method can be overridden when its class is inherited.

  3. A final variable's value cannot be changed.

  4. The keywords final and finally have the same meaning in Java.

  5. Final class can be abstract in Java.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. No

  2. Yes

  3. DTD's are recommendation only

  4. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

DTD's do not follow the inheritance principle, as they do not form any relationship. So other options are wrong.

Multiple choice
  1. classes only

  2. methods only

  3. data members only

  4. classes, methods and data members

  5. interfaces only

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. integers

  2. final

  3. protected

  4. private

  5. string

Reveal answer Fill a bubble to check yourself
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.