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
-
Advice
-
Pointcut
-
Weaving
-
Jointpoint
C
Correct answer
Explanation
Weaving is the process of applying aspects (cross-cutting concerns) to a target object to create a proxy object. Advice defines what action to take, Pointcut defines where to apply, and Jointpoint is a point in execution.
A
Correct answer
Explanation
The instanceof operator in Java tests whether an object is an instance of a specified class, interface, or array type. It returns true if the object is an instance of the specified type or any subtype. This is a fundamental type-checking mechanism in Java's type system.
D
Correct answer
Explanation
A single .NET DLL (assembly) can contain many classes - there is no limit. DLLs are assemblies that can hold multiple types including classes, interfaces, structs, and enums. The organization of classes within a DLL is flexible and depends on the application's architecture needs.
-
Server-side code
-
Client-side code
-
Both A) and B)
-
None of the above
A
Correct answer
Explanation
Code-behind files in ASP.NET contain server-side code that executes on the web server, not in the user's browser. This includes event handlers, business logic, and data access code. Client-side code would be in JavaScript or script tags in the .aspx page.
A
Correct answer
Explanation
An abstract class in object-oriented programming can declare constructors. Although you cannot instantiate an abstract class directly using the new keyword, its constructor is executed during the initialization chain of a concrete subclass when the subclass is instantiated, allowing initialization of shared fields.
-
List,HashSet
-
Queue
-
Stack
-
LinkedList
-
All the above
E
Correct answer
Explanation
Generic classes in C# and other languages include List, HashSet, Queue, Stack, and LinkedList - all of which are type-safe collection classes. These classes allow you to specify the type of elements they will store when you create an instance. Since all the listed options (A, B, C, D) are valid examples of generic classes, 'All the above' is the correct answer.
-
Property Object
-
Property Name
-
Property Value
-
Dynamic Property
A
Correct answer
Explanation
In QTP/UFT, using Description.Create() instantiates a Properties collection object (often referred to as a Description object or Property Object) that dynamically defines object properties. It is not a single property name, a single property value, or a dynamic property itself.
A
Correct answer
Explanation
In Java and similar object-oriented languages supporting single inheritance, a class can inherit from only one parent class (abstract or concrete) to avoid the diamond problem. However, it can implement multiple interfaces to achieve multiple inheritance of type, making the statement entirely true.
-
Classes
-
Methods
-
Interfaces
-
Events
-
All of the above
E
Correct answer
Explanation
Generics in .NET can be applied to classes (List), methods (generic functions), interfaces (IComparable), delegates (which relate to events), and structs. Since all the listed types can use generics, 'All of the above' is correct.
-
Data Access Object
-
Transfer Object
-
Business Delegate
-
Adapter
D
Correct answer
Explanation
The Adapter pattern allows classes with incompatible interfaces to work together by wrapping one object to match another's interface. It converts the interface of a class into another interface clients expect, enabling unrelated classes to collaborate without modifying their source code.
-
Hashtable
-
ArrayList
-
Heap
-
Stack
C
Correct answer
Explanation
VB.Net provides several collection types including Hashtable (key-value pairs), ArrayList (dynamic array), and Stack (LIFO collection). Heap is NOT a collection type in VB.Net or .NET - it's a memory management structure used internally by the runtime, not a class that developers use directly for storing and retrieving data in their applications.
-
Using FRIEND Keyword
-
Using STATIC Keyword
-
Using SHARED Keyword
-
NONE
C
Correct answer
Explanation
In VB.NET, the Shared keyword allows methods (and other members) to be called without creating an instance of the class. This is equivalent to the 'static' keyword in languages like C# or Java. Option A (FRIEND) is an access modifier that controls visibility, not whether an instance is required.
-
Casting
-
DirectCast
-
InheritenceCast
-
LevelCasting
B
Correct answer
Explanation
In VB.NET, DirectCast is used for casting reference types up and down the inheritance hierarchy. It is more efficient than CType when the conversion type is known at compile time because it avoids runtime type checking overhead. Option A is too generic; Options C and D are not valid VB.NET keywords.
A
Correct answer
Explanation
In Java and C#, the static keyword denotes that a member belongs to the class itself rather than instances of the class. Consequently, only one copy of a static member exists in memory, shared across all objects of that class type, whereas non-static members are created per object.
B
Correct answer
Explanation
A final class in Java cannot be extended (inherited from). The final keyword prevents subclassing by design. This is used when you want to prevent modification or extension of a class for security, design, or performance reasons.