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. data binding

  2. polymorphism

  3. encapsulation

  4. inheritance

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

Encapsulation is the OOP principle of hiding implementation details (data and method internals) from users of the class. This allows the class designer to modify internal implementation without affecting code that uses the class, as long as the public interface remains stable. Data binding, polymorphism, and inheritance are related but distinct concepts.

Multiple choice
  1. public

  2. private

  3. protected

  4. none of these

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

In C++ inheritance, a protected member of the base class remains protected in the derived class when inherited in public mode. Public inheritance preserves the access level of protected members - they stay protected, not public. Private inheritance would make them private, and protected inheritance would keep them protected.

Multiple choice
  1. A static function can have access to only other static members declared in the same class.

  2. A static function can be called using the class name instead of its objects.

  3. The keyword static is used before the function name.

  4. None of the above.

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

All statements A, B, and C are correct about static member functions: they can only access other static members, can be called using class name, and the static keyword appears before the return type in declaration (not before the function name). Since all individual statements are true, 'None of the above' is technically incorrect, making D the answer choice.

Multiple choice
  1. True

  2. False

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

Polymorphism in OOP allows objects of different classes to be treated as objects of a common superclass. The core concept is one interface (function/operator name) with multiple implementations (forms). This includes function overloading, operator overloading, and virtual functions.

Multiple choice
  1. Base class-B Derived class-C

  2. Base class-A & B Derived class-C

  3. Base class-A Derived class-B & C

  4. Base class-A Derived class-C

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

Class C uses multiple inheritance, inheriting from both class A and class B (syntax: class C: public A,B). This makes A and B the base classes and C the derived class. Multiple inheritance allows a class to inherit from multiple base classes simultaneously.

Multiple choice
  1. the same as an abstract class

  2. a data type that cannot be instantiated

  3. a data type which can be used only by the defined operation

  4. a data type on which operation defined can not use it

  5. All of the above

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

Correct answer; only the operation defined can use it.

Multiple choice
  1. a member of class

  2. type of class

  3. instance of class

  4. independent like the class

  5. part of the class

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

Yes, in an object oriented programming language, an object is instance/variable of class. So, this option is correct.