Computer Knowledge
Object-Oriented Programming
2,239 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
-
An instance of the Student class
-
The course variable
-
The gradeStudent method
-
The ID variable
-
The name variable
B,C,D,E
Correct answer
Explanation
In Java inheritance, a subclass inherits all accessible instance variables (name, ID, course) and methods (gradeStudent) from its superclass. It does not inherit an instance - that's not how inheritance works.
-
mMemberAttribute
-
mmemberAttribute
-
MemberAttribute
-
member_attribute
A
Correct answer
Explanation
mMemberAttribute follows the class attribute guideline - 'm' prefix indicates member variable, followed by camelCase. mmemberAttribute (double m), MemberAttribute (no prefix), and member_attribute (snake_case) all violate the naming convention.
-
DataMemberAttribute, Public
-
ServiceContractAttribute, Public
-
DataMemberAttribute,Private
-
DataContractAttribute,Public
A
Correct answer
Explanation
DataContractSerializer serializes members marked with DataMemberAttribute regardless of access level (public or private). XmlSerializer only serializes public members by default. This is a key distinction - DataContract gives you more control over what gets serialized, while XmlSerializer follows traditional .NET serialization patterns.
-
Inversion Injection
-
Dependency Injection
-
Setter Injection
-
Pattern Injection
B
Correct answer
Explanation
Inversion of Control (IoC) is a design principle where the flow of control is inverted compared to traditional programming. Dependency Injection is a common implementation pattern for achieving IoC - dependencies are provided to objects rather than objects creating them. Setter Injection and Constructor Injection are specific types of Dependency Injection.
-
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.
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.