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. Constant declarations of public, static, and final are optional in any combination.

  2. An interface can have only abstract methods and no concrete methods are allowed.

  3. A class implementing an interface can itself be abstract.

  4. A class can implement any number of interfaces.

  5. All of the above

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

All of the above are correct statements.

Multiple choice
  1. Default members can be accessed only by classes in the same package.

  2. Protected members can be accessed by other classes in the same package only.

  3. A protected member inherited by a subclass within another package is not accessible to any other class.

  4. Public members are not accessible in other packages.

  5. Both (2) and (4)

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

Public members are accessible everywhere whether in the current package or different.

Multiple choice
  1. a member function

  2. a class

  3. an operator

  4. a data item

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

A member function is a function that is defined within a class scope. These functions operate on objects of the class and can access private and protected members. Member functions define the behavior and operations that objects of the class can perform.

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
D Correct answer
Multiple choice
  1. Making C+ operators work with objects

  2. Giving C++ operators more than they can handle

  3. Giving new meanings to existing C++ operators

  4. Making new C++ operators

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

Operator overloading allows programmers to define custom behavior for existing C++ operators when used with user-defined types (objects). For example, you can overload the + operator to work with string objects to concatenate them. Option C correctly describes this as giving new meanings to existing operators. Options A and B are misleading, and D is incorrect because you cannot create entirely new operators - only redefine existing ones.

Multiple choice
  1. Nine

  2. Eight

  3. Seven

  4. Six

  5. Five

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

There are 6 subclasses of reader Class in Java. These are 1) BufferedReader for buffering other readers 2) ChararrayReader for reading from char array 3) FilterReader for readin filter streams 4) InputStreamReader for reading a character stream 5) PipedReader for reading from pipe 6) StringReader for reading from a string.So this is the correct answer.