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. Map

  2. HashMap

  3. HashTable

  4. Table

  5. Arrays

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

Map is a data structure which is used to put data as key value pair for quick retrieval. So it is an interface.

Multiple choice
  1. Packages contain a single package statement.

  2. Packages can contain any number of import statements.

  3. Packages contain a single public class consisting of main() function declaration.

  4. Packages contain any number of classes private to the package.

  5. Packages can contain any number of package declarations.

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

This statement is the essential one as execution of the program starts from main() function, which is to be defined in any particular class with public access.

Multiple choice
  1. Inheritance

  2. Encapsulation and information hiding

  3. Class hierarchy

  4. Polymorphism

  5. Software analysis

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

This is the principle of concealing internal data and procedures of an object, and providing an interface to each object in such a way that it reveals very little information about its inner working.

Multiple choice
  1. Removing the private modifier from the two () method

  2. Adding the public modifier to the declaration of class X

  3. Changing the private modifier on the declaration of the one() method to protect

  4. Removing the Y () constructor

  5. None of these

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

This change will also not allow the code to compile because there is no error in that constructor.

Multiple choice
  1. X Only

  2. Y Only

  3. Z Only

  4. X and Z

  5. X and Y

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

This is the correct choice as if a class doesn’t explicitly declare the default constructor, java compiler automatically creates a non-argument constructor for that class. So, a default constructor for class X will be created at run time automatically. So, this answer is true.