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 technology programming languages
  1. Class

  2. Interface

  3. None

  4. Thread

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

Java does not support multiple inheritance of classes (to avoid the diamond problem), but it does support multiple inheritance of interfaces. A class can implement multiple interfaces, inheriting their contracts. This is how Java achieves multiple inheritance functionality while avoiding implementation complexity.

Multiple choice technology web technology
  1. Serialized

  2. OptionalAttribute

  3. NonSerializable

  4. Deserialized

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

The [NonSerialized] attribute in .NET prevents a specific field from being serialized during the serialization process. This is useful for fields that contain runtime-only data, sensitive information, or data that should not persist between sessions. The other options are not valid attributes for preventing serialization.

Multiple choice technology programming languages
  1. The Set interface

  2. list stores elements in an ordered way but may contain duplicate elements

  3. List interface provides support for ordered collections of objects.

  4. All of the above

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

The List interface in Java represents an ordered collection (or sequence) of elements that permits duplicates. The correct option accurately describes its support for ordered collections. Comparing List to Set is wrong since Set does not allow duplicates, meaning the 'All of the above' option is incorrect.

Multiple choice technology programming languages
  1. AbstractList

  2. List

  3. Array

  4. All of the Above

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

ArrayList extends AbstractList directly, which in turn extends AbstractCollection. List is an interface that AbstractList implements, not a parent class. Array is a separate language feature (fixed-size) unrelated to ArrayList's inheritance hierarchy.

Multiple choice technology programming languages
  1. ArrayList( )

  2. ArrayList(Collection c)

  3. ArrayList(int capacity)

  4. All of the Above

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

ArrayList has three constructors: a no-arg constructor creating an empty list with default capacity (10), one accepting a Collection to initialize with elements, and one accepting an initial capacity integer. All three are valid and commonly used.

Multiple choice technology programming languages
  1. Class

  2. Interface

  3. Abstract Class

  4. All of the above

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

ArrayList is a concrete class in Java's Collections Framework, implementing the List interface. It is not an interface itself, nor is it abstract. Students often confuse it with the List interface it implements.

Multiple choice technology web technology
  1. function

  2. static

  3. static function

  4. public function

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

The 'static' keyword in many programming languages (including PHP, which this appears to be from) allows a method or property to be accessed without instantiating the class. A 'static function' can be called directly using ClassName::methodName() without creating an object. Options A and B alone are incorrect syntax - it must be 'static function' together.

Multiple choice technology testing
  1. True

  2. False

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

The statement is false. Identification properties in QTP are properties that QTP uses to uniquely identify objects in the application under test. They're not defined within the application itself but are determined by QTP's object identification mechanism based on properties like name, class, etc.

Multiple choice technology web technology
  1. private constructor classname()

  2. public constructor classname()

  3. private function classname()

  4. public function classname()

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

ActionScript constructors are defined as public functions with the same name as the class. They don't use the 'constructor' keyword (that's a naming convention in some languages, not ActionScript syntax), and constructors cannot be private.

Multiple choice technology programming languages
  1. When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.

  2. When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.

  3. When an instance of File is garbage collected, the corresponding file on the local file system is deleted.

  4. None of the above.

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Multiple choice technology programming languages
  1. This is implemented method

  2. This is overrided method

  3. Compile time Error

  4. Run time error

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

This is Java polymorphism in action. The interface reference 'mi' points to an object of class B. At runtime, the JVM calls the overridden show() method in class B, not the one in class A. This demonstrates dynamic method dispatch - the actual method executed depends on the object type, not the reference type.

Multiple choice technology programming languages
  1. Constructor

  2. Destructor

  3. Overloaded assignment operator

  4. Default Copy Constructor

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

The question is poorly worded and technically inaccurate. C++ provides exactly 4 special member functions by default: default constructor, copy constructor, copy assignment operator, and destructor. A 'destructor' is always supplied (not user-defined), but the question seems to confuse 'supplied with' with 'compiler-generated'. All four options are technically provided by the compiler, but 'Destructor' wording is misleading.

Multiple choice technology programming languages
  1. This is A

  2. This is B

  3. Nothing will be printed as output

  4. None of the above

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

The code fails to compile because the overriding method show() in subclass B has a more restrictive access modifier (protected) than the overridden public method in class A. Because of this compilation error, no output is produced, making 'None of the above' correct.