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. declare a member function that is defined in a subclass

  2. designate the absence of a type

  3. declare objects that can be modified outside of program control

  4. declare a synonym for an existing type

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

Multiple choice
  1. avoid arguments between classes

  2. allow access to classes whose source code is unavailable

  3. allow one class to access an unrelated class

  4. increase the versatility of an member function

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

Multiple choice
  1. The package definition must come first

  2. Class should be private

  3. Method should be without void

  4. None of these

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