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. An indexer is always an instance member, but a property can be static also.

  2. A property is always an instance member, but An indexer can be static also.

  3. Indexers can not be participate in inheritance, properties can also participate in inheritance

  4. No difference

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

In C#, indexers cannot be static because they are designed to index instance data using this, whereas properties can be declared static. The other options are incorrect because both properties and indexers can participate in inheritance.

Multiple choice technology programming languages
  1. True

  2. False

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

Abstract methods declare method signatures without implementation. Non-abstract child classes must provide concrete implementations. Abstract child classes can choose to implement abstract methods or declare them abstract again for their own children to implement.

Multiple choice technology programming languages
  1. Structures can be used as a base for other structures.

  2. A structure can implement one or more interfaces.

  3. Structure members can be methods, fields, indexers, properties, operator methods, and events.

  4. Structures can also define constructors, but not destructors. And you cannot define a default (parameterless) constructor for a structure.

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

In C#, structs cannot inherit from other structures or classes, but they can implement interfaces, define constructors (though parameterless constructors have specific restrictions depending on the C# version), and contain members like methods, properties, and events. Since this is an MC-2 (multiple response) question, all three selected options are correct statements.

Multiple choice technology programming languages
  1. Can not use in structs

  2. A derivation constraint

  3. A default constructor constraint

  4. A reference/value type constraint

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

Generic constraints in C# restrict type parameters. Derivation constraints specify a base class, constructor constraints require a parameterless constructor, and reference/value type constraints constrain to class or struct. Generic constraints CAN be used with structs - they're not limited to classes.

Multiple choice technology programming languages
  1. True

  2. False

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

C# does allow static methods to use generic type parameters. The type parameter can be defined at the class level (all methods share it) or at the method level (only that method uses it). Static methods can both access class-level type parameters and define their own method-specific type parameters.

Multiple choice technology security
  1. Java sand box environment provides protection against decompilation

  2. Java is compiled into ELF binaries and cannot be decompiled

  3. Java byte code can always be decompiled, code obfuscators can make the reverse engineering process more time confusing but cannot prevent it

  4. Java is difficult to decompile because the Just-In-Time compiler automatically perform string encryption by default

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

Java bytecode can always be decompiled back to readable source code using tools like JD-GUI or CFR. Code obfuscators make reverse engineering more difficult by renaming variables and obscuring logic, but cannot prevent decompilation entirely.

Multiple choice technology security
  1. Java sand box environment provides protection against decompilation

  2. Java is compiled into ELF binaries and cannot be decompiled

  3. Java byte code can always be decompiled, code obfuscators can make the reverse engineering process more time confusing but cannot prevent it

  4. Java is difficult to decompile because the Just-In-Time compiler automatically perform string encryption by default

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

Java compiles to bytecode, not native ELF binaries. Bytecode can be decompiled back to readable Java code using widely-available tools. Code obfuscators rename variables and scramble control flow to slow down reverse engineering, but they cannot prevent decompilation entirely. The sandbox provides runtime security, not compilation protection.

Multiple choice technology web technology
  1. String

  2. System

  3. Final

  4. Object

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

In Java, the Object class is at the top of the class hierarchy - every class implicitly extends Object (except Object itself, which has no superclass). This provides common methods like equals(), hashCode(), toString(), and getClass() to all objects. String and System are classes that inherit from Object, while Final is a keyword, not a class.

Multiple choice technology
  1. True

  2. False

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

Static methods belong to the class, not instances. Hiding (not overriding) occurs when a subclass declares a static method with the same signature - it's resolved at compile-time based on reference type, not runtime object type.