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
-
The object module
-
The class module
-
The form module
-
The global module
A
Correct answer
Explanation
The question asks which item is NOT a collection in VB project structure. Option A (object module) is marked correct, meaning it's not part of standard VB project collections. The standard VB project includes class modules, form modules, and global modules as collections. However, the terminology here is potentially confusing as object-oriented programming is central to VB.
-
Access is limited to current assembly
-
Access is limited to the containing class or types derived from containing class
-
Access is limited to the containing type
-
Access is limited to current assembly or types derived from the containing class.
D
Correct answer
Explanation
The protected internal access modifier in C# combines two access levels: protected AND internal. Members marked protected internal can be accessed from within the same assembly OR from derived classes (even in different assemblies). It's a union of both access modifiers, not an intersection.
-
List ,HashSet
-
Queue
-
Stack
-
LinkedList
-
All of Above
E
Correct answer
Explanation
All the listed options (List, HashSet, Queue, Stack, LinkedList) are generic classes in C#. They are type-safe collections that can work with any data type specified at compile time. Generic classes improve code reusability and type safety by allowing you to define classes with type parameters.
-
Public
-
Private
-
Protected
-
Internal
D
Correct answer
Explanation
Top-level (non-nested) classes in C# default to internal access. They are accessible only within the same assembly unless explicitly declared public. They cannot be private or protected at the top level - these modifiers only apply to nested class members.
-
An abstract class may only contain on complete method
-
An interface may contain complete or incomplete method
-
A class may inherit several interfaces , A class may inherit only one abstract class.
-
A class implementation an abstract class has to implement all methods of abstract class , but same is not required in case of an interface.
-
All
C
Correct answer
Explanation
A primary difference in object-oriented programming is that a class can implement multiple interfaces but can inherit from only one abstract class (single inheritance). Distractors are incorrect because abstract classes can have multiple implemented methods, and classes must implement all members of any interface they implement.
-
Yes
-
No, because the interface name does not start with 'I'
-
No, because MyProp is not declared as public
-
No, because interfaces can't contain property declaration
A
Correct answer
Explanation
The code compiles correctly. Interface members are implicitly public and abstract, so explicitly writing 'public' is unnecessary but allowed. The 'I' prefix is a naming convention (like IMyInterface) but not required by the language. Properties in interfaces are valid and must include at least a getter.
-
Access is limited to current assembly
-
Access is limited to the containing class or types derived from containing class
-
Access is limited to the containing type
-
Access is limited to current assembly or types derived from the containing class.
D
Correct answer
Explanation
The 'protected internal' access modifier in C# allows access within the current assembly or by types derived from the containing class. It combines the scope of protected and internal modifiers.
-
List ,HashSet
-
Queue
-
Stack
-
LinkedList
-
All of Above
E
Correct answer
Explanation
In .NET, List, HashSet, Queue, Stack, and LinkedList are all built-in generic collection classes located in the System.Collections.Generic namespace. They allow type-safe collections of items, making 'All of Above' the correct selection since every listed class is a generic class.
-
Public
-
Private
-
Protected
-
Internal
D
Correct answer
Explanation
For top-level classes in C# that are not nested, the default access modifier is 'internal', meaning they are accessible only within the current assembly. Other default access modifiers exist for nested classes and members.
-
An abstract class may only contain on complete method
-
An interface may contain complete or incomplete method
-
A class may inherit several interfaces , A class may inherit only one abstract class.
-
A class implementation an abstract class has to implement all methods of abstract class , but same is not required in case of an interface.
-
All
C
Correct answer
Explanation
A key difference between interfaces and abstract classes is that a class can implement multiple interfaces (multiple inheritance) but inherit only one abstract class (single inheritance). This is fundamental to understanding their different purposes in C#.
-
Yes
-
No, because the interface name does not start with 'I'
-
No, because MyProp is not declared as public
-
No, because interfaces can't contain property declaration
A
Correct answer
Explanation
The code compiles successfully. Interface naming conventions suggest starting with 'I', but this is not a requirement for compilation. The property is implicitly public in interfaces, so it's properly declared.
-
Operational Oriented Programming
-
Object Operational Programming
-
Object Oriented Proffesional Programming
-
Object Oriented Programming
D
Correct answer
Explanation
OOP stands for Object-Oriented Programming, which is a programming paradigm based on the concept of objects. The other options are incorrect expansions of the OOP acronym.
-
A field always has Get and Set Methods
-
A property always has Get and Set Methods
-
Both 1 and 2
-
None of the above
D
Correct answer
Explanation
Neither fields nor properties always have Get and Set methods. In .NET, fields are direct variable members and have no methods. Properties can have Get only, Set only, both, or neither (in rare cases like write-only properties). Therefore, statements A and B are both incorrect, making D the correct answer.
B
Correct answer
Explanation
Transfer Objects can be passed over the network using various serialization mechanisms (Java serialization, XML, JSON, etc.). While implementing java.io.Serializable is one common approach, it's not strictly necessary - other serialization frameworks can be used. The statement is too absolute.
-
Public
-
Private
-
Protected
-
Unintialized
B
Correct answer
Explanation
In C++, the default access specifier for class members (both data members and member functions) is 'private'. This means that unless explicitly specified as public or protected, class members are only accessible within the class itself. This is a fundamental principle of encapsulation in object-oriented programming with C++ classes. 'Unintialized' is not an access specifier - it's a state, not a visibility modifier.