Programming Fundamentals Questions and Answers PDF
Document Details

Uploaded by StrongJubilation4064
Tags
Summary
This document is a set of practice questions and answers covering foundational programming concepts. It addresses topics like literals, constructors, mutability, declaration, and initialization. Review these questions to reinforce your grasp of core programming principles.
Full Transcript
1. Literals True/False: A literal is a hardcoded value written directly into the source code. Answer: True. Explanation: Literals are fixed values (like numbers or strings) that appear directly in the code without requiring computation. Fill in the Blank: An ______ literal is used to directly...
1. Literals True/False: A literal is a hardcoded value written directly into the source code. Answer: True. Explanation: Literals are fixed values (like numbers or strings) that appear directly in the code without requiring computation. Fill in the Blank: An ______ literal is used to directly create an object by writing its key–value pairs inside curly braces. Answer: object. Explanation: An object literal uses curly braces to specify properties immediately rather than constructing the object via a function. Multiple Choice: Which of the following is an example of a literal? A) new Number(42) B) "Hello, World!" C) parseInt("42") D) Math.PI Answer: B) "Hello, World!" Explanation: Option B is written directly as a string value in the code, making it a literal. 2. Constructor True/False: A constructor is a special function used to initialize new objects. Answer: True. Explanation: Constructors set up a new object’s properties and initial state when it is created. Fill in the Blank: In many object-oriented languages, the keyword ______ is used within a constructor to refer to the current object instance. Answer: this. Explanation: The keyword "this" refers to the current object being created or manipulated. Multiple Choice: Which statement best describes a constructor? A) It creates a new variable without initializing it. B) It is used only for inheritance. C) It sets up a new object’s initial state. D) It destroys an object after use. Answer: C) It sets up a new object’s initial state. Explanation: Constructors prepare new objects by initializing their properties. 3. Immutability True/False: An immutable value cannot be altered once it is created. Answer: True. Explanation: Immutability means that the value stays constant after it’s set. Fill in the Blank: In an immutable data structure, any operation that appears to change it will instead return a ______ version of the structure. Answer: new. Explanation: Operations on immutable structures create new copies rather than modifying the original. Multiple Choice: Which of the following is typically immutable? A) Arrays in JavaScript B) Strings in many languages C) Objects in Python D) Lists in Ruby Answer: B) Strings in many languages. Explanation: Many programming languages treat strings as immutable to preserve consistency and avoid side effects. 4. Mutability True/False: A mutable object can be modified after its creation. Answer: True. Explanation: Mutability allows an object’s state or properties to change over time. Fill in the Blank: When an object is ______, its state can be changed without creating a new instance. Answer: mutable. Explanation: Mutable objects permit in-place modifications. Multiple Choice: Which example best illustrates mutability? A) A fixed integer value B) A string literal C) A list that you can append items to D) A constant expression Answer: C) A list that you can append items to. Explanation: Lists (in many languages) allow changes such as appending or removing elements. 5. Declaration True/False: Declaration is the process of introducing a variable name into a program’s scope. Answer: True. Explanation: Declarations create a variable identifier without necessarily assigning a value. Fill in the Blank: Declaring a variable means creating an identifier without necessarily assigning it an ______. Answer: initial value. Explanation: A declaration reserves a name in the code, while initialization assigns a value. Multiple Choice: Which of the following best describes a declaration? A) Assigning a value to a variable B) Introducing a new variable name in code C) Changing a variable’s value D) Removing a variable from memory Answer: B) Introducing a new variable name in code. Explanation: Declaration brings a variable into existence within a given scope. 6. Initialization True/False: Initialization always occurs at the same time as declaration. Answer: False. Explanation: A variable can be declared first and initialized later; they are conceptually different steps. Fill in the Blank: Initialization is the process of ______ a variable with its first value. Answer: assigning. Explanation: Initialization gives the declared variable an initial value. Multiple Choice: Which code snippet shows both declaration and initialization? A) int x; B) x = 10; C) int x = 10; D) 10 = x; Answer: C) int x = 10;. Explanation: This snippet both declares the variable and assigns it an initial value. 7. Reassignment True/False: Reassignment is the act of giving an already declared variable a new value. Answer: True. Explanation: Reassignment changes the value stored in a variable after it has been initialized. Fill in the Blank: After a variable is initialized, changing its value is known as ______. Answer: reassignment. Explanation: This term specifically refers to updating the value of an existing variable. Multiple Choice: What does the following code demonstrate? javascript Copy Edit let count = 5; count = 10; A) Declaration B) Initialization C) Reassignment D) Hoisting Answer: C) Reassignment. Explanation: The value of count is being updated from its initial value. 8. Variables True/False: Variables are storage locations identified by a name that holds data values. Answer: True. Explanation: Variables act as containers for storing and referencing data in memory. Fill in the Blank: Variables declared with ______ in some languages are block-scoped. Answer: let (or const). Explanation: In languages like JavaScript, let and const limit a variable’s accessibility to the block where it’s declared. Multiple Choice: Which of the following is NOT a common characteristic of variables? A) They store data. B) They have a scope. C) They always represent functions. D) They can be reassigned (if mutable). Answer: C) They always represent functions. Explanation: Variables can store any type of data, not only functions. 9. Hoisting True/False: Hoisting refers to the process where both variable declarations and initializations are moved to the top of their scope. Answer: False. Explanation: In JavaScript, only the declarations are hoisted; initializations remain in place. Fill in the Blank: In JavaScript, only the ______ of a variable declared with var is hoisted. Answer: declaration. Explanation: Only the fact that the variable exists is hoisted, not its assigned value. Multiple Choice: What is hoisting in JavaScript? A) Running code before compilation B) Moving variable and function declarations to the top of their scope C) Automatically converting types D) Creating global variables Answer: B) Moving variable and function declarations to the top of their scope. Explanation: Hoisting rearranges the code during compilation so that declarations are known before execution. 10. Scope True/False: Scope determines where variables and functions are accessible in a program. Answer: True. Explanation: Scope limits the visibility of variables and functions to certain parts of the code. Fill in the Blank: Variables declared inside a function are in the ______ scope of that function. Answer: local. Explanation: Local scope confines variables to the function in which they are declared. Multiple Choice: Which of the following best describes block scope? A) Variables are accessible anywhere in the program B) Variables are confined within curly braces C) Variables are accessible only in the global environment D) Variables are only declared, not defined Answer: B) Variables are confined within curly braces. Explanation: Block scope means that variables only exist within the block (e.g., within an if statement or loop) where they are declared. 11. TDZ (Temporal Dead Zone) True/False: The Temporal Dead Zone (TDZ) refers to the time between entering a scope and when a let/const variable is declared. Answer: True. Explanation: The TDZ is a period where variables exist in theory but cannot be accessed until declared. Fill in the Blank: Accessing a variable in its TDZ will result in a ______ error. Answer: Reference. Explanation: Trying to use a variable before its declaration in the TDZ throws a ReferenceError. Multiple Choice: Which declaration is affected by the TDZ? A) var B) let C) function D) None of the above Answer: B) let. Explanation: Variables declared with let (and const) have a TDZ; var does not. 12. Objects True/False: Objects are collections of key–value pairs used to represent structured data. Answer: True. Explanation: Objects bundle related data together in properties and methods. Fill in the Blank: In an object literal, keys are paired with values using a ______. Answer: colon. Explanation: The colon separates each key from its corresponding value in the literal syntax. Multiple Choice: Which statement about objects is false? A) They can contain functions as values. B) They are always immutable by default. C) They can be created using literal notation. D) They can have nested objects. Answer: B) They are always immutable by default. Explanation: By default, objects are mutable unless specific measures are taken to make them immutable. 13. References True/False: In many languages, assigning an object to a variable stores a reference to that object rather than a copy of it. Answer: True. Explanation: A variable holds the memory address of the object, so changes through one reference are seen by all. Fill in the Blank: When two variables reference the same object, changes via one variable will be visible through the ______ variable. Answer: other. Explanation: Since both variables point to the same object, modifications affect the single shared instance. Multiple Choice: Which of the following best explains references? A) They copy the entire object B) They point to the memory location of the object C) They are used only in functional programming D) They automatically clone objects Answer: B) They point to the memory location of the object. Explanation: A reference simply points to where the object resides in memory rather than duplicating it. 14. Mutation True/False: Mutation means modifying the state or data within an object. Answer: True. Explanation: Mutation involves changing the properties or content of an existing object. Fill in the Blank: An operation that changes an object in place is called ______. Answer: mutation. Explanation: Mutation directly alters the object's state instead of creating a new object. Multiple Choice: Which scenario is an example of mutation? A) Reassigning a variable to a new object B) Changing a property value within an existing object C) Declaring a new variable D) Copying an object Answer: B) Changing a property value within an existing object. Explanation: Option B demonstrates altering the state of an already existing object. 15. Type Coercion True/False: Type coercion is the implicit conversion of values from one data type to another. Answer: True. Explanation: Many languages (like JavaScript) automatically convert types when operators expect a different type. Fill in the Blank: When a language performs ______ coercion, it automatically converts one data type into another without explicit instructions. Answer: implicit. Explanation: Implicit coercion happens automatically as part of language rules during evaluation. Multiple Choice: Which of the following is an example of type coercion in JavaScript? A) "5" + 2 resulting in "52" B) parseInt("5") + 2 resulting in 7 C) Using Number("5") D) All of the above Answer: A) "5" + 2 resulting in "52". Explanation: In option A, JavaScript automatically converts the number 2 to a string, leading to concatenation. 16. Type Conversion True/False: Type conversion always refers to explicit conversion by the programmer. Answer: False. Explanation: Type conversion can be either explicit (by the programmer) or implicit (automatically by the language). Fill in the Blank: Converting a value from one type to another using a function like Number() is an example of ______ conversion. Answer: explicit. Explanation: Here, the programmer intentionally converts the type, which is explicit conversion. Multiple Choice: Which method is used for type conversion in many languages? A) Implicit conversion B) Explicit conversion functions like parseInt() or String() C) Automatic type deduction D) None of the above Answer: B) Explicit conversion functions like parseInt() or String(). Explanation: These functions clearly signal that a conversion is being performed. 17. Explicit Conversion True/False: Explicit conversion requires the programmer to manually convert a value from one type to another. Answer: True. Explanation: The programmer directly calls a conversion function, making the intent clear. Fill in the Blank: Using a function such as ______ to convert a string to a number is an example of explicit conversion. Answer: Number (or parseInt). Explanation: The function explicitly transforms the input into a number. Multiple Choice: What is the main advantage of explicit conversion? A) It is faster than implicit conversion B) It avoids ambiguity by clearly stating the conversion C) It always returns the original value D) It happens automatically Answer: B) It avoids ambiguity by clearly stating the conversion. Explanation: Explicit conversion leaves no doubt about the programmer’s intent. 18. Implicit Coercion True/False: Implicit coercion happens automatically without the programmer’s explicit instruction. Answer: True. Explanation: The language converts types on its own when needed by context. Fill in the Blank: Implicit coercion may lead to ______ results if the language’s rules are not well understood. Answer: unexpected. Explanation: Automatic conversions can sometimes produce results that differ from programmer expectations. Multiple Choice: Which of the following is a risk associated with implicit coercion? A) Code clarity is improved. B) It can introduce subtle bugs due to unexpected type conversions. C) It forces the programmer to be explicit. D) It eliminates the need for unit tests. Answer: B) It can introduce subtle bugs due to unexpected type conversions. Explanation: Implicit coercion may change types in ways that are hard to track, leading to bugs. 19. Functions True/False: Functions are reusable blocks of code that can accept inputs and return outputs. Answer: True. Explanation: Functions encapsulate code logic so it can be called repeatedly with different inputs. Fill in the Blank: In many programming languages, functions are considered ______ citizens because they can be passed as arguments. Answer: first-class. Explanation: First-class functions are treated as values that can be assigned, passed, and returned. Multiple Choice: Which of the following is NOT a property of functions? A) They encapsulate logic B) They can be recursive C) They cannot return a value D) They can be passed as arguments Answer: C) They cannot return a value. Explanation: Functions can return values; saying they cannot is incorrect. 20. Expressions True/False: An expression is any valid unit of code that resolves to a value. Answer: True. Explanation: Expressions are evaluated to produce data, making them fundamental units in programming. Fill in the Blank: The statement 2 + 3 is an example of an arithmetic ______. Answer: expression. Explanation: It computes a value (5) and is therefore an expression. Multiple Choice: Which of the following is an example of an expression? A) if (x > 0) {... } B) return; C) x * y D) var x; Answer: C) x * y. Explanation: This arithmetic operation evaluates to a value, qualifying it as an expression. 21. Arguments True/False: Arguments are the actual values passed to a function during a call. Answer: True. Explanation: When you call a function, the provided values are known as arguments. Fill in the Blank: In the function call sum(3, 4), the numbers 3 and 4 are called ______. Answer: arguments. Explanation: They are the specific values supplied to the function parameters. Multiple Choice: Which of the following best describes arguments? A) Placeholders in function definitions B) Values provided to a function when it is invoked C) The names of parameters in a function D) None of the above Answer: B) Values provided to a function when it is invoked. Explanation: Arguments are the real data passed to functions during a call. 22. Statements True/False: A statement is an instruction that performs an action but may not necessarily produce a value. Answer: True. Explanation: Statements control program behavior (like loops or conditionals) without needing to resolve to a value. Fill in the Blank: In many languages, a statement ends with a ______ (such as a semicolon). Answer: delimiter. Explanation: A delimiter (e.g., semicolon) signifies the end of a statement. Multiple Choice: Which of the following is a statement? A) 3 + 4 B) let x = 10; C) "Hello" D) x > 5 Answer: B) let x = 10;. Explanation: This line declares and initializes a variable, serving as an instruction. 23. HOFs (Higher-Order Functions) True/False: Higher-order functions can take other functions as arguments or return them. Answer: True. Explanation: Higher-order functions operate on functions, allowing for more abstract and modular code. Fill in the Blank: Functions like map, filter, and reduce are common examples of ______ functions. Answer: higher-order. Explanation: They either accept functions as parameters or return functions, qualifying as higher-order. Multiple Choice: Which statement is true about higher-order functions? A) They can only accept primitive types. B) They enable function composition and abstraction. C) They cannot return functions. D) They are only used in object-oriented programming. Answer: B) They enable function composition and abstraction. Explanation: Higher-order functions allow for composing complex operations in a clear and concise manner. 24. Iterations True/False: Iteration is the process of repeating a block of code until a condition is met. Answer: True. Explanation: Iteration enables repetitive tasks by executing code multiple times. Fill in the Blank: Using a ______ loop is a common way to perform iteration in many programming languages. Answer: for (or while). Explanation: Loops such as for-loops or while-loops are the standard methods for iterating. Multiple Choice: Which of the following best describes iteration? A) Executing code concurrently B) Repeating operations multiple times C) Executing code once D) Compiling code into machine language Answer: B) Repeating operations multiple times. Explanation: Iteration focuses on repeatedly executing a set of instructions. 25. Loops True/False: Loops are control structures that repeatedly execute code based on a condition. Answer: True. Explanation: Loops provide a means to execute code repeatedly while a condition remains true. Fill in the Blank: A ______ loop executes its block at least once before checking the condition. Answer: do-while. Explanation: In a do-while loop, the code block is executed first and then the condition is checked. Multiple Choice: Which loop type checks the condition before each iteration? A) do-while loop B) while loop C) for loop D) All of the above Answer: B) while loop. Explanation: The while loop checks the condition at the beginning of each cycle before executing its body. 26. Iterable True/False: An iterable is any object that can be looped over, such as arrays or strings. Answer: True. Explanation: Iterables implement protocols (like Symbol.iterator in JavaScript) that allow their elements to be accessed sequentially. Fill in the Blank: In JavaScript, an object is iterable if it implements the ______ method. Answer: Symbol.iterator. Explanation: This method is the standard by which JavaScript determines if an object can be iterated. Multiple Choice: Which of the following is typically NOT iterable? A) Arrays B) Objects (plain objects) C) Strings D) Maps Answer: B) Objects (plain objects are not iterable by default). Explanation: Plain objects do not implement an iterator by default, so they cannot be looped over using iteration constructs like for-of. 27. Control Flow True/False: Control flow determines the order in which code statements are executed. Answer: True. Explanation: Control flow structures (such as conditionals and loops) guide the path of execution in a program. Fill in the Blank: Conditional statements and loops are constructs that manage ______ flow in a program. Answer: control. Explanation: These constructs explicitly dictate how the program’s execution path is directed. Multiple Choice: Which of the following is NOT a control flow structure? A) if/else B) switch C) for loop D) variable assignment Answer: D) variable assignment. Explanation: Variable assignment is an action, not a structure that directs the execution order. 28. Synchronous True/False: Synchronous operations are executed one after another, blocking subsequent code until completion. Answer: True. Explanation: Synchronous code waits for each operation to finish before moving on, which can cause blocking behavior. Fill in the Blank: In a ______ model, tasks are executed sequentially, with each task waiting for the previous one to finish. Answer: synchronous. Explanation: The synchronous model executes tasks one after the other, without overlap. Multiple Choice: Which is a characteristic of synchronous code? A) It allows multiple operations to run concurrently. B) Each operation must complete before the next begins. C) It uses callbacks for every operation. D) It always runs in the background. Answer: B) Each operation must complete before the next begins. Explanation: Synchronous code is inherently sequential, ensuring each step is completed in order. 29. Asynchronous True/False: Asynchronous operations allow other code to run while waiting for long-running tasks to complete. Answer: True. Explanation: Asynchronous programming lets the system continue executing other code instead of waiting for operations like I/O to finish. Fill in the Blank: The use of callbacks, promises, or async/await are common approaches to handling ______ code. Answer: asynchronous. Explanation: These constructs manage operations that occur out-of-sequence without blocking execution. Multiple Choice: Which of the following best describes asynchronous programming? A) Code that executes in a blocking manner B) Code that executes concurrently, improving responsiveness C) Code that only runs on the server D) Code that cannot handle I/O operations Answer: B) Code that executes concurrently, improving responsiveness. Explanation: Asynchronous programming allows multiple operations to proceed without waiting for each to finish sequentially. 30. Abstraction True/False: Abstraction involves hiding the complex reality while exposing only the necessary parts of an object or system. Answer: True. Explanation: Abstraction reduces complexity by allowing you to interact with simplified interfaces. Fill in the Blank: In programming, abstraction helps reduce complexity by focusing on ______ details. Answer: essential. Explanation: It hides unneeded details so that you can concentrate on what’s important. Multiple Choice: Which statement best describes abstraction? A) It increases the complexity of code. B) It is only used in low-level programming. C) It simplifies interaction with complex systems by exposing a simpler interface. D) It removes all details from a system. Answer: C) It simplifies interaction with complex systems by exposing a simpler interface. Explanation: Abstraction allows you to use complex systems without needing to understand every detail. 31. Algorithm True/False: An algorithm is a step-by-step procedure for solving a problem. Answer: True. Explanation: Algorithms are the recipes or instructions that solve specific computational problems. Fill in the Blank: The efficiency of an algorithm is often measured in terms of time and ______ complexity. Answer: space. Explanation: Both time and space complexity are key metrics to assess algorithm performance. Multiple Choice: Which of the following is an example of an algorithm? A) A function that sorts an array B) A variable declaration C) A user interface D) A file stored on disk Answer: A) A function that sorts an array. Explanation: Sorting is a common algorithmic problem with specific step-by-step methods. 32. API (Application Programming Interface) True/False: An API defines a set of protocols for building and interacting with software applications. Answer: True. Explanation: APIs provide standardized methods and rules for software components to interact. Fill in the Blank: APIs allow different software systems to ______ with each other. Answer: communicate. Explanation: The main role of an API is to facilitate communication between systems. Multiple Choice: Which of the following is NOT a typical function of an API? A) Enabling data exchange B) Hiding internal implementation details C) Directly modifying hardware components D) Providing standardized methods for interaction Answer: C) Directly modifying hardware components. Explanation: APIs abstract functionality; they do not directly alter hardware. 33. Bug True/False: A bug is an error or flaw in a program that causes unexpected behavior. Answer: True. Explanation: Bugs are mistakes in code that lead to incorrect or unexpected program behavior. Fill in the Blank: The process of finding and fixing bugs is known as ______. Answer: debugging. Explanation: Debugging is the systematic process of locating and correcting errors. Multiple Choice: Which statement about bugs is correct? A) Bugs always crash the program immediately. B) Bugs can lead to security vulnerabilities. C) Bugs are only found during compilation. D) Bugs improve performance. Answer: B) Bugs can lead to security vulnerabilities. Explanation: Bugs may expose security flaws that attackers can exploit. 34. Class True/False: A class is a blueprint for creating objects, defining properties and methods. Answer: True. Explanation: Classes provide a template for objects, specifying common properties and behaviors. Fill in the Blank: In object-oriented programming, a ______ is an instance of a class. Answer: object. Explanation: An object is created from a class, embodying its structure and behavior. Multiple Choice: Which of the following best describes a class? A) A data structure that holds only primitive values B) A template for creating objects with similar properties and behaviors C) A function that cannot have methods D) A mechanism for asynchronous programming Answer: B) A template for creating objects with similar properties and behaviors. Explanation: Classes serve as blueprints to produce objects with defined attributes and methods. 35. Compilation True/False: Compilation is the process of translating source code into machine code. Answer: True. Explanation: Compilers convert high-level language code into a form that can be executed by the machine. Fill in the Blank: A ______ is the program that performs the compilation of source code. Answer: compiler. Explanation: A compiler reads source code and generates the corresponding machine-level instructions. Multiple Choice: Which of the following is a characteristic of compilation? A) It happens at runtime. B) It converts high-level code into a lower-level language before execution. C) It is the same as interpretation. D) It cannot optimize code. Answer: B) It converts high-level code into a lower-level language before execution. Explanation: Compilation prepares code for execution by translating it before the program runs. 36. Compiler True/False: A compiler translates code from a high-level language to a low-level language such as machine code. Answer: True. Explanation: This translation is essential for the computer to understand and execute the code. Fill in the Blank: The main role of a compiler is to ______ code for execution by the computer’s processor. Answer: translate. Explanation: Translation is at the core of a compiler’s function. Multiple Choice: Which is NOT a responsibility of a compiler? A) Syntax checking B) Optimization of code C) Running the program D) Generating executable code Answer: C) Running the program. Explanation: The compiler translates code; executing it is the role of the runtime environment. 37. Data Structures True/False: Data structures are ways to organize and store data for efficient access and modification. Answer: True. Explanation: They determine how data is stored and accessed, impacting performance. Fill in the Blank: Common data structures include arrays, lists, trees, and ______. Answer: graphs. Explanation: Graphs are another common data structure used to model relationships. Multiple Choice: Which of the following is considered a data structure? A) A loop B) A function C) A binary tree D) A variable declaration Answer: C) A binary tree. Explanation: A binary tree is a structured way to organize data hierarchically. 38. Debugging True/False: Debugging is the process of identifying and fixing errors in a program. Answer: True. Explanation: Debugging involves systematically finding and correcting issues in code. Fill in the Blank: A ______ debugger helps developers step through code to locate bugs. Answer: software (or interactive). Explanation: A debugger is a tool that lets you observe code execution to identify problems. Multiple Choice: Which tool is commonly used for debugging? A) Text editor B) Version control system C) Integrated Development Environment (IDE) D) Compiler Answer: C) Integrated Development Environment (IDE). Explanation: IDEs often include built-in debugging tools to facilitate this process. 39. Dependency Injection True/False: Dependency injection is a design pattern where an object’s dependencies are provided externally rather than created within the object. Answer: True. Explanation: This pattern decouples object creation from usage, making code more modular and testable. Fill in the Blank: Dependency injection promotes ______ by decoupling the creation of dependencies from their usage. Answer: modularity. Explanation: It makes components more independent and easier to test. Multiple Choice: Which benefit is most associated with dependency injection? A) Tighter coupling between components B) Easier testing and maintainability C) Increased memory usage D) Automatic compilation Answer: B) Easier testing and maintainability. Explanation: By injecting dependencies, you can swap them out for mocks in tests, simplifying maintenance. 40. Encapsulation True/False: Encapsulation is the bundling of data and methods that operate on the data into a single unit. Answer: True. Explanation: Encapsulation hides internal details and exposes only necessary components. Fill in the Blank: Encapsulation helps protect an object’s internal state from ______ access. Answer: unauthorized. Explanation: It prevents external code from altering internal properties directly. Multiple Choice: What is a key benefit of encapsulation? A) It exposes all implementation details. B) It reduces complexity and increases reusability. C) It eliminates the need for classes. D) It forces global variable usage. Answer: B) It reduces complexity and increases reusability. Explanation: Encapsulation ensures that objects manage their own state, making code easier to maintain and reuse. 41. Exception Handling True/False: Exception handling is a mechanism to manage runtime errors gracefully. Answer: True. Explanation: It allows programs to recover or fail gracefully when errors occur. Fill in the Blank: A block of code that catches exceptions is typically labeled ______ in many languages. Answer: catch. Explanation: The “try…catch” structure is standard for handling exceptions. Multiple Choice: Which of the following is a common keyword in exception handling? A) try B) loop C) switch D) import Answer: A) try. Explanation: The try block is used to wrap code that might throw an exception. 42. Framework True/False: A framework provides a pre-built structure and set of tools to build applications. Answer: True. Explanation: Frameworks offer reusable components and conventions to speed up development. Fill in the Blank: A framework can drastically reduce development time by providing common ______ and patterns. Answer: functionalities. Explanation: By reusing prebuilt functionality, you don’t have to write common code from scratch. Multiple Choice: Which of the following is an example of a web development framework? A) React (library) B) Angular C) jQuery D) Node.js (runtime) Answer: B) Angular. Explanation: Angular is a full-fledged framework that provides structure and tools for building web applications. 43. Garbage Collection True/False: Garbage collection is the automated process of reclaiming memory from objects that are no longer in use. Answer: True. Explanation: Garbage collection helps prevent memory leaks by freeing memory automatically. Fill in the Blank: Languages like Java and C# use ______ collection to manage memory automatically. Answer: garbage. Explanation: Garbage collection is built into these languages to handle memory cleanup. Multiple Choice: What is the main purpose of garbage collection? A) To compile code B) To free up memory by removing unreachable objects C) To create new objects D) To perform exception handling Answer: B) To free up memory by removing unreachable objects. Explanation: Garbage collection ensures that unused memory is reclaimed, keeping the system efficient. 44. Inheritance True/False: Inheritance allows one class to acquire properties and methods of another class. Answer: True. Explanation: Inheritance promotes code reuse by letting a class inherit features from a parent class. Fill in the Blank: In object-oriented programming, a subclass inherits from a ______ class. Answer: superclass. Explanation: The parent class is known as the superclass from which the child class derives. Multiple Choice: Which of the following is an advantage of inheritance? A) Code duplication increases B) It allows for code reuse and hierarchical organization C) It restricts polymorphism D) It prevents encapsulation Answer: B) It allows for code reuse and hierarchical organization. Explanation: Inheritance makes it easier to build on existing code and organize related classes. 45. IDE (Integrated Development Environment) True/False: An IDE typically includes a code editor, debugger, and build automation tools. Answer: True. Explanation: IDEs consolidate multiple development tools into one application for efficiency. Fill in the Blank: An IDE helps streamline the development process by providing integrated ______. Answer: tools. Explanation: By integrating tools like editors, debuggers, and build systems, an IDE simplifies coding. Multiple Choice: Which of the following is an example of an IDE? A) Visual Studio Code B) Git C) Chrome D) Docker Answer: A) Visual Studio Code. Explanation: Visual Studio Code is a popular IDE (or code editor with IDE features) that includes many integrated tools. 46. Interface True/False: An interface defines a contract of methods that a class must implement without specifying how they are implemented. Answer: True. Explanation: Interfaces specify what methods should exist, leaving the implementation details to the class. Fill in the Blank: In many languages, an interface specifies ______ that a class should implement. Answer: method signatures. Explanation: It only outlines the names and parameters of methods without their body. Multiple Choice: What is a key benefit of using interfaces? A) They enforce a particular implementation. B) They allow different classes to be used interchangeably if they implement the same interface. C) They automatically generate code. D) They remove the need for error handling. Answer: B) They allow different classes to be used interchangeably if they implement the same interface. Explanation: Interfaces promote polymorphism by ensuring consistent method availability across classes. 47. Library True/False: A library is a collection of prewritten code that developers can call upon to perform common tasks. Answer: True. Explanation: Libraries provide reusable code modules, saving time by avoiding rewriting common functionality. Fill in the Blank: Using a library allows you to avoid ______ code from scratch. Answer: reinventing. Explanation: Libraries offer ready-to-use solutions so you don't have to develop them independently. Multiple Choice: Which statement about libraries is false? A) They provide reusable functionality. B) They are integrated into every programming language by default. C) They can be imported into your project. D) They help reduce development time. Answer: B) They are integrated into every programming language by default. Explanation: Libraries are additional code bases and are not always built into the language itself. 48. OOP (Object-Oriented Programming) True/False: OOP is a programming paradigm that organizes code around objects and data rather than actions and logic. Answer: True. Explanation: OOP centers on objects that encapsulate data and behavior, structuring programs around them. Fill in the Blank: The four pillars of OOP are encapsulation, inheritance, polymorphism, and ______. Answer: abstraction. Explanation: Abstraction is one of the key concepts that simplify complex systems by focusing on relevant details. Multiple Choice: Which of the following is NOT a core principle of OOP? A) Encapsulation B) Inheritance C) Recursion D) Polymorphism Answer: C) Recursion. Explanation: Recursion is a programming technique, not a fundamental principle of object-oriented programming. 49. Polymorphism True/False: Polymorphism allows methods to have different implementations based on the object calling them. Answer: True. Explanation: Polymorphism enables one interface to be used for different underlying forms, enhancing flexibility. Fill in the Blank: In OOP, polymorphism enables objects to be treated as instances of their ______ class. Answer: parent (or base). Explanation: Polymorphism allows objects of subclasses to be treated as objects of their superclass. Multiple Choice: Which scenario best demonstrates polymorphism? A) A function that only accepts integers B) A method overridden in multiple subclasses C) A variable declared without initialization D) A loop that iterates over an array Answer: B) A method overridden in multiple subclasses. Explanation: Overriding methods in subclasses is a classic example of polymorphism. 50. Recursion True/False: Recursion occurs when a function calls itself to solve a problem. Answer: True. Explanation: Recursion breaks a problem down into smaller instances by having a function call itself. Fill in the Blank: A recursive function must have a ______ condition to prevent infinite recursion. Answer: base. Explanation: The base condition stops the recursive calls and prevents a stack overflow. Multiple Choice: Which is a risk of using recursion? A) Improved code readability B) Excessive memory usage leading to a stack overflow C) Reduced execution time D) Increased code simplicity in all cases Answer: B) Excessive memory usage leading to a stack overflow. Explanation: Without a proper base case, recursive calls can consume too much stack memory. 51. Runtime True/False: Runtime refers to the period when a program is executing. Answer: True. Explanation: Runtime is the duration when the program is running, as opposed to compile time. Fill in the Blank: Errors that occur during the execution of a program are known as ______ errors. Answer: runtime. Explanation: These errors appear only when the code is running, not when it is compiled. Multiple Choice: Which term is most associated with the concept of runtime? A) Compilation B) Execution C) Declaration D) Refactoring Answer: B) Execution. Explanation: Runtime and execution refer to the period when the program is actually performing its operations. 52. Syntax True/False: Syntax refers to the rules that define the structure of a programming language. Answer: True. Explanation: Syntax rules determine how code must be written to be valid in a language. Fill in the Blank: A syntax ______ occurs when the code does not follow the language’s grammatical rules. Answer: error. Explanation: Syntax errors prevent the code from being compiled or interpreted correctly. Multiple Choice: Which of the following is primarily concerned with syntax? A) Code style B) Compiler errors C) Algorithm efficiency D) Memory management Answer: B) Compiler errors. Explanation: Syntax errors are typically reported by the compiler when code does not follow the proper format. 53. Semantic True/False: Semantics in programming refers to the meaning and behavior of code constructs rather than their structure. Answer: True. Explanation: Semantics deals with what the code does, not just how it is written. Fill in the Blank: While syntax is about how code is written, ______ is about what the code does. Answer: semantics. Explanation: Semantics provides the logic and meaning behind code execution. Multiple Choice: Which statement is true about semantics? A) Semantic errors are usually caught by the compiler. B) Semantics deal with logic and meaning in code. C) Syntax errors are more difficult to debug than semantic errors. D) Semantics are irrelevant in modern programming languages. Answer: B) Semantics deal with logic and meaning in code. Explanation: Understanding semantics is crucial because it governs how the code behaves during execution. 54. Concurrency True/False: Concurrency involves multiple tasks making progress at overlapping time periods. Answer: True. Explanation: Concurrency allows tasks to be interleaved, which can improve efficiency even on a single processor. Fill in the Blank: Concurrency can be achieved by interleaving the execution of ______ tasks. Answer: multiple. Explanation: By handling multiple tasks in overlapping time slices, a program can appear to do several things at once. Multiple Choice: Which of the following best describes concurrency? A) Tasks that run in parallel on multiple processors B) Tasks that are executed in a strictly sequential order C) Tasks that can be executed out-of-order but are conceptually simultaneous D) None of the above Answer: C) Tasks that can be executed out-of-order but are conceptually simultaneous. Explanation: Concurrency means tasks are managed in a way that they overlap in execution without necessarily running at the exact same time. 55. Parallelism True/False: Parallelism is the simultaneous execution of multiple computations. Answer: True. Explanation: Parallelism requires hardware (multiple cores or processors) to truly execute tasks at the same time. Fill in the Blank: Parallelism is often used to improve performance by utilizing multiple ______ or cores. Answer: processors. Explanation: Multiple processors allow tasks to run concurrently, reducing overall execution time. Multiple Choice: Which of the following distinguishes parallelism from concurrency? A) Parallelism requires simultaneous hardware execution. B) Parallelism always leads to race conditions. C) Concurrency does not involve time slicing. D) Concurrency is only used in single-threaded applications. Answer: A) Parallelism requires simultaneous hardware execution. Explanation: Parallelism physically runs tasks at the same time, unlike concurrency which may interleave them. 56. Immutable Data Structures True/False: Immutable data structures cannot be changed after they are created. Answer: True. Explanation: Immutable data structures are designed to remain constant, helping avoid unintended side effects. Fill in the Blank: In an immutable data structure, operations return a ______ copy rather than modifying the original. Answer: new. Explanation: Any change to an immutable structure results in a new instance, preserving the original state. Multiple Choice: Which is a benefit of using immutable data structures? A) They always consume less memory. B) They simplify debugging in concurrent environments. C) They allow for arbitrary mutation. D) They are faster in all cases. Answer: B) They simplify debugging in concurrent environments. Explanation: Immutable structures prevent side effects and race conditions, making concurrent code easier to reason about. 57. Functional Programming True/False: Functional programming treats computation as the evaluation of mathematical functions and avoids changing state. Answer: True. Explanation: This paradigm emphasizes pure functions and immutability to create predictable code. Fill in the Blank: A key concept in functional programming is the use of ______ functions. Answer: pure. Explanation: Pure functions have no side effects and always produce the same output for the same input. Multiple Choice: Which of the following is a common characteristic of functional programming? A) Heavy reliance on mutable state B) Use of higher-order functions and immutability C) Lack of support for recursion D) No support for modularity Answer: B) Use of higher-order functions and immutability. Explanation: Functional programming emphasizes immutability and functions that can be passed around like data. 58. Event-Driven Programming True/False: In event-driven programming, the flow of the program is determined by events such as user actions or messages. Answer: True. Explanation: This paradigm waits for events to occur, then executes corresponding event handlers. Fill in the Blank: An ______ is an action or occurrence that can trigger a function in event-driven systems. Answer: event. Explanation: Events (like clicks or keystrokes) are the triggers that drive program behavior in this model. Multiple Choice: Which of the following best describes event-driven programming? A) Code runs in a predetermined, linear sequence B) Code execution is triggered by external events C) It is only used in synchronous systems D) It eliminates the need for user interaction Answer: B) Code execution is triggered by external events. Explanation: In event-driven systems, external events dictate when and how code is executed. 59. Design Patterns True/False: Design patterns are reusable solutions to common problems in software design. Answer: True. Explanation: Design patterns capture proven solutions that can be adapted to recurring design challenges. Fill in the Blank: The Singleton, Observer, and Factory patterns are examples of ______ patterns. Answer: design. Explanation: These patterns provide standardized ways to solve common architectural problems. Multiple Choice: Which statement is true about design patterns? A) They provide a one-size-fits-all solution to any problem. B) They offer best practices that can be adapted to solve recurring design issues. C) They are specific to one programming language. D) They always result in more complex code. Answer: B) They offer best practices that can be adapted to solve recurring design issues. Explanation: Design patterns are flexible guidelines rather than rigid rules, helping improve code design. 60. Version Control True/False: Version control systems help track changes and manage collaboration on source code over time. Answer: True. Explanation: They allow developers to review history, merge changes, and collaborate effectively. Fill in the Blank: Git is an example of a ______ control system. Answer: version. Explanation: Git is a widely used system that manages versions of code. Multiple Choice: Which of the following is NOT a benefit of using version control? A) Tracking changes over time B) Facilitating collaboration among developers C) Automatically optimizing code performance D) Managing multiple code branches Answer: C) Automatically optimizing code performance. Explanation: Version control systems track changes but do not optimize code performance. 61. Testing (Unit, Integration, System) True/False: Unit testing focuses on testing individual components in isolation. Answer: True. Explanation: Unit tests are designed to verify that each part of the program works as expected independently. Fill in the Blank: Integration testing verifies that multiple components work together as expected, while ______ testing evaluates the entire system. Answer: system. Explanation: System testing checks the complete, integrated application for overall behavior. Multiple Choice: Which level of testing is most concerned with the overall behavior of the application? A) Unit testing B) Integration testing C) System testing D) Regression testing Answer: C) System testing. Explanation: System testing evaluates the end-to-end operation of the complete system. 62. Refactoring True/False: Refactoring involves restructuring existing code without changing its external behavior. Answer: True. Explanation: The purpose of refactoring is to improve code quality while preserving functionality. Fill in the Blank: The primary goal of refactoring is to improve code ______ and maintainability. Answer: readability. Explanation: By making code clearer and better organized, it becomes easier to maintain and extend. Multiple Choice: Which is a common reason to refactor code? A) To add new features B) To simplify complex code for better understanding C) To increase the number of lines of code D) To fix syntax errors Answer: B) To simplify complex code for better understanding. Explanation: Refactoring aims to simplify the structure of code without altering its behavior. 63. Documentation True/False: Documentation provides detailed information about how a program works and how to use it. Answer: True. Explanation: Good documentation is key to understanding and maintaining code over time. Fill in the Blank: Good documentation is essential for maintaining code, especially when new developers need to ______ a project. Answer: understand. Explanation: Clear documentation helps new team members quickly grasp the functionality and structure of the code. Multiple Choice: Which of the following best describes the purpose of documentation? A) To confuse users with technical jargon B) To serve as a reference that explains code functionality and usage C) To replace well-written code D) To ensure that code compiles without errors Answer: B) To serve as a reference that explains code functionality and usage. Explanation: Documentation guides developers and users by explaining how the code works and how to use it effectively.