


































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



































































Question 1. Which programming paradigm emphasizes describing what the program should accomplish rather than how to accomplish it? A) Imperative programming B) Procedural programming C) Declarative programming D) Event‑driven programming Answer: C Explanation: Declarative programming focuses on the desired results, leaving the execution details to the language runtime. Question 2. In an imperative language, which construct directly changes program state? A) Function declaration B) Variable assignment C) Interface definition D) Abstract class Answer: B Explanation: Assigning a new value to a variable mutates the program’s state. Question 3. Which of the following is a characteristic of structural programming? A) Use of GOTO statements B) Unrestricted jumps between code blocks C) Use of nested loops and conditionals only D) Dynamic code generation at runtime Answer: C Explanation: Structural programming restricts flow control to loops, conditionals, and subroutines, avoiding arbitrary jumps. Question 4. In event‑driven programming, what typically triggers the execution of a handler? A) Compilation of the source file
B) A user clicking a button C) Declaration of a variable D) Execution of a for‑loop Answer: B Explanation: Event handlers respond to external events such as user actions. Question 5. Which primitive data type is most appropriate for representing true/false values? A) int B) char C) bool D) double Answer: C Explanation: The bool type stores logical true or false. Question 6. What is the size of a 32‑bit integer in most modern languages? A) 8 bits B) 16 bits C) 32 bits D) 64 bits Answer: C Explanation: A 32‑bit integer occupies 32 bits of memory. Question 7. Which type is stored on the stack rather than the heap? A) String (reference type) B) Array of objects C) Struct (value type) D) List Answer: C
B) list.CopyTo() C) new List(list) D) list.DeepCopy() Answer: C Explanation: The constructor that takes an IEnumerable creates a shallow copy. Question 12. What is the result of the following C# cast? int x = (int)3.7; A) 3 B) 4 C) Compile‑time error D) 3. Answer: A Explanation: Explicit casting from double to int truncates the fractional part. Question 13. Which conversion is performed implicitly by the compiler? A) double to int B) int to double C) string to int D) bool to int Answer: B Explanation: An int can be widened to a double automatically. Question 14. Which statement best describes a reference type variable? A) It stores the actual data value. B) It contains a memory address pointing to the data. C) It cannot be null. D) It always resides on the stack. Answer: B
Explanation: Reference type variables hold a reference (pointer) to the actual object on the heap. Question 15. Which of the following control structures is not a loop? A) for B) while C) do‑while D) switch Answer: D Explanation: switch performs multi‑way branching, not iteration. Question 16. How many times will the body of a do‑while loop execute at minimum? A) Zero B) One C) Two D) Depends on the condition Answer: B Explanation: The condition is evaluated after the first execution, guaranteeing at least one run. Question 17. Which logical operator returns true only when both operands are true? A) && (AND) B) || (OR) C) ^ (XOR) D)! (NOT) Answer: A Explanation: The AND operator requires both sides to be true. Question 18. What does the XOR (^) operator return when both operands are true? A) True
Explanation: Encapsulation bundles fields and methods within a class. Question 22. What access modifier allows members to be visible only within the same class and its derived classes? A) public B) private C) protected D) internal Answer: C Explanation: protected members are accessible to subclasses. Question 23. Which keyword is used in C# to inherit from a base class? A) implements B) extends C) : (colon) after the class name D) inherits Answer: C Explanation: The colon syntax specifies the base class. Question 24. If class Dog derives from class Animal, which statement is true? A) Dog can access private members of Animal. B) Animal can access private members of Dog. C) Dog inherits public and protected members of Animal. D) Dog must implement all methods of Animal even if they are not abstract. Answer: C Explanation: Subclasses inherit the accessible members (public/protected) of the base class. Question 25. Which concept allows a method to have many different implementations depending on the object’s runtime type?
A) Overloading B) Overriding C) Encapsulation D) Composition Answer: B Explanation: Overriding enables polymorphic behavior at runtime. Question 26. What is the result of calling a virtual method on a base‑class reference that points to a derived object? A) The base‑class implementation executes. B) The derived‑class implementation executes. C) Compile‑time error. D) No method is executed. Answer: B Explanation: Virtual dispatch selects the most derived override. Question 27. Which OOP principle hides complex implementation details behind a simple interface? A) Inheritance B) Polymorphism C) Abstraction D) Encapsulation Answer: C Explanation: Abstraction provides a high‑level view while concealing inner workings. Question 28. Which of the following best describes a static method? A) It can only be called on an instance of the class. B) It belongs to the class itself, not any particular object. C) It must be overridden in derived classes.
Question 32. Which of the following best describes global scope? A) Accessible only within a single method B) Accessible throughout the entire program file C) Accessible only within the class that defines it D) Accessible only inside a namespace Answer: B Explanation: Global variables (or static fields) can be referenced from any code in the same assembly. Question 33. What does the try block do in exception handling? A) Declares a new exception type B) Executes code that might throw an exception C) Catches all exceptions automatically D) Guarantees that no exceptions will occur Answer: B Explanation: Code inside try is monitored for runtime exceptions. Question 34. Which clause catches exceptions of type ArgumentNullException? A) catch (Exception e) B) catch (ArgumentNullException e) C) finally (ArgumentNullException e) D) when (ArgumentNullException) Answer: B Explanation: Specific catch blocks match the declared exception type. Question 35. Which statement about the finally block is true? A) It executes only when an exception is thrown. B) It executes only when no exception occurs. C) It always executes regardless of whether an exception is thrown.
D) It must re‑throw the caught exception. Answer: C Explanation: finally runs after try/catch completes, in all cases. Question 36. In memory management, where are method call frames stored? A) Heap B) Stack C) Data segment D) Code segment Answer: B Explanation: The call stack holds activation records for each method invocation. Question 37. Which of the following is true about the heap? A) It stores value‑type variables only. B. It is automatically reclaimed without any runtime support. C. Objects allocated on the heap are accessed via references. D. It grows only when the program starts. Answer: C Explanation: Reference‑type instances live on the heap and are accessed through pointers. Question 38. What triggers garbage collection in a managed runtime? A. Explicit delete statements B. When the stack overflows C. When the runtime determines that memory is low or an object is unreachable D. At compile time Answer: C Explanation: The GC reclaims memory for objects that are no longer reachable.
C. Using it in arithmetic expressions D. Declaring it inside a method Answer: B Explanation: const fields are immutable after compile‑time initialization. Question 43. Which operator is used to concatenate strings in C#? A. + B. & C.. (dot) D. :: Answer: A Explanation: The + operator joins two string operands. Question 44. Which of the following statements about tuples in C# is correct? A. Tuples are reference types. B. Tuples can be deconstructed into separate variables. C. Tuples require a custom class definition. D. Tuples cannot contain more than three elements. Answer: B Explanation: Tuples support deconstruction syntax (var (a,b) = tuple;). Question 45. What will Console.WriteLine(5 / 2); output in C#? A. 2. B. 2 C. 3 D. Compile‑time error Answer: B Explanation: Integer division truncates the remainder.
Question 46. Which loop guarantees at least one execution regardless of the condition? A. for B. while C. do‑while D. foreach Answer: C Explanation: The condition is evaluated after the body runs. Question 47. In a switch statement, what keyword is used to exit the block early? A. exit B. break C. continue D. return Answer: B Explanation: break ends the current case and exits the switch. Question 48. Which statement about enum types is true? A. They can inherit from other enums. B. Their underlying type defaults to int. C. They must be declared inside a class. D. They cannot be used in a switch. Answer: B Explanation: Enums are integral types, defaulting to int. Question 49. Which access modifier makes a member visible only within the same assembly? A. public B. private
Question 53. Which of these statements about abstract classes is false? A. They can contain concrete methods. B. They can be instantiated directly. C. They may define abstract methods without bodies. D. They can serve as base classes. Answer: B Explanation: Abstract classes cannot be instantiated. Question 54. In C#, what does the params keyword allow? A. Passing arguments by reference. B. Passing a variable‑length argument list as an array. C. Declaring a method that returns multiple values. D. Defining a generic method. Answer: B Explanation: params creates a parameter array for variable numbers of arguments. Question 55. Which of the following is a reference type in C#? A. int B. double C. bool D. string Answer: D Explanation: string is a reference type (although immutable). Question 56. What does the new operator do when applied to a class? A. Allocates memory on the stack. B. Calls the class’s static constructor only.
C. Allocates an object on the heap and invokes its constructor. D. Performs a deep copy of an existing object. Answer: C Explanation: new creates a heap‑allocated instance and runs its constructor. Question 57. Which statement about boxing in C# is correct? A. Boxing converts a reference type to a value type. B. Boxing creates a copy of a value type on the heap. C. Boxing is performed automatically for all types. D. Boxing eliminates the need for garbage collection. Answer: B Explanation: Boxing wraps a value type in an object, allocating it on the heap. Question 58. Which of the following removes the need for explicit memory deallocation? A. Manual delete statements B. Reference counting only C. Garbage collection D. Stack allocation only Answer: C Explanation: Garbage collectors automatically reclaim unreachable objects. Question 59. Which statement about tail call optimization is true for the C# compiler? A. It is guaranteed for all recursive calls. B. It is performed only in debug builds. C. It is not performed by the C# compiler but may be done by the JIT. D. It requires the tailcall keyword. Answer: C Explanation: The C# compiler does not emit tail‑call instructions; the CLR JIT may optimize them.
B. NullPointerException C. IndexOutOfRangeException D. ArgumentException Answer: A Explanation: Java distinguishes checked exceptions like IOException; C# treats all exceptions as unchecked. Question 64. In C#, which collection type guarantees O(1) access by index? A. List B. LinkedList C. Queue D. Stack Answer: A Explanation: List is backed by an array, providing constant‑time index access. Question 65. Which of the following statements about readonly fields is false? A. They can be assigned in the constructor. B. They can be assigned at the point of declaration. C. Their value can be changed after construction. D. They are immutable for the lifetime of the object. Answer: C Explanation: readonly fields cannot be modified after the constructor finishes. Question 66. Which operator is used to test for reference equality in C#? A. == B. Equals() C. ReferenceEquals() D. ===
Answer: C Explanation: Object.ReferenceEquals checks if two references point to the same object. Question 67. Which of the following best describes method hiding? A. Using the override keyword. B. Declaring a new method with the same name using the new keyword. C. Overloading a method with different parameters. D. Declaring a method as abstract. Answer: B Explanation: new creates a new member that hides the base class member. Question 68. Which of these is a value type that can also be nullable? A. int? B. string? C. object? D. List? Answer: A Explanation: Nullable value types are expressed with ? after the type (e.g., int?). Question 69. Which statement about the dynamic keyword in C# is true? A. It provides compile‑time type safety. B. It bypasses compile‑time type checking and resolves at runtime. C. It can only be used with value types. D. It forces early binding. Answer: B Explanation: dynamic defers member resolution to runtime. Question 70. Which of the following is a sealed method?