Q.1 Which of the following is an example of an object-oriented programming language?
C
Java
Assembly
Fortran
Explanation - Java supports classes, objects, inheritance, and polymorphism, making it an object-oriented language.
Correct answer is: Java
Q.2 What is the main principle of functional programming?
Mutability
Stateful computation
Pure functions
Global variables
Explanation - Functional programming emphasizes the use of pure functions with no side effects.
Correct answer is: Pure functions
Q.3 In procedural programming, programs are primarily structured around:
Objects
Procedures/Functions
Events
Modules
Explanation - Procedural programming is based on procedures or functions that operate on data.
Correct answer is: Procedures/Functions
Q.4 Which programming paradigm is most associated with event-driven user interfaces?
Procedural
Object-Oriented
Event-Driven
Functional
Explanation - Event-driven programming responds to user actions like clicks or key presses.
Correct answer is: Event-Driven
Q.5 Which of the following best describes 'encapsulation'?
Binding data and methods together
Dividing a program into functions
Responding to events
Using recursion
Explanation - Encapsulation in OOP bundles data and methods into a single unit called a class.
Correct answer is: Binding data and methods together
Q.6 Which paradigm avoids mutable data and side effects?
Object-Oriented
Functional
Procedural
Imperative
Explanation - Functional programming avoids mutable data and side effects for predictability and correctness.
Correct answer is: Functional
Q.7 The DRY principle in software development stands for:
Do Repeat Yourself
Don’t Repeat Yourself
Double Recursion Yield
Dynamic Resource Yield
Explanation - DRY emphasizes reducing code duplication for maintainability.
Correct answer is: Don’t Repeat Yourself
Q.8 Which of these is a best practice in programming?
Hardcoding values
Using meaningful variable names
Avoiding comments
Mixing concerns
Explanation - Readable code with meaningful variable names improves maintainability and reduces bugs.
Correct answer is: Using meaningful variable names
Q.9 Polymorphism in OOP allows:
Functions with same name to behave differently
Functions with no return value
A class to have multiple parents
Multiple loops in code
Explanation - Polymorphism enables the same method name to act differently based on context.
Correct answer is: Functions with same name to behave differently
Q.10 Which paradigm focuses on describing what to compute rather than how to compute?
Imperative
Declarative
Object-Oriented
Procedural
Explanation - Declarative programming focuses on the 'what' rather than the 'how' of computation.
Correct answer is: Declarative
Q.11 What is the purpose of code refactoring?
To rewrite code in a new language
To optimize code performance without changing behavior
To add new features
To remove comments
Explanation - Refactoring improves code structure and readability without altering functionality.
Correct answer is: To optimize code performance without changing behavior
Q.12 Which of these is an example of a declarative programming language?
Python
C++
SQL
Java
Explanation - SQL is declarative since users specify what they want retrieved, not how.
Correct answer is: SQL
Q.13 Which principle suggests keeping classes focused on a single responsibility?
Open/Closed Principle
Single Responsibility Principle
Liskov Substitution
Dependency Inversion
Explanation - SRP states that each class should have only one reason to change.
Correct answer is: Single Responsibility Principle
Q.14 Which of the following is NOT an OOP concept?
Inheritance
Polymorphism
Encapsulation
Compilation
Explanation - Compilation is a process, not an OOP principle.
Correct answer is: Compilation
Q.15 In imperative programming, programs are described as:
Statements changing program state
Mathematical expressions
Logical constraints
Objects and classes
Explanation - Imperative programming relies on statements that modify state step by step.
Correct answer is: Statements changing program state
Q.16 Which of these improves code reusability?
Hardcoding values
Copy-pasting code
Using functions and classes
Avoiding modularization
Explanation - Functions and classes allow reusable and modular code.
Correct answer is: Using functions and classes
Q.17 The term 'side effect' in functional programming refers to:
Code that is inefficient
Code that modifies state outside its scope
Extra comments in code
Unused variables
Explanation - Side effects occur when a function interacts with external state.
Correct answer is: Code that modifies state outside its scope
Q.18 Which programming paradigm is used in Prolog?
Logic Programming
Functional
Object-Oriented
Procedural
Explanation - Prolog uses rules and facts, making it a logic programming language.
Correct answer is: Logic Programming
Q.19 Which design principle promotes loose coupling in code?
Dependency Inversion
Encapsulation
Polymorphism
Recursion
Explanation - Dependency Inversion Principle encourages depending on abstractions rather than details.
Correct answer is: Dependency Inversion
Q.20 What is the advantage of modular programming?
Faster typing
Improved maintainability and reusability
More bugs
No need for testing
Explanation - Modular programming divides a program into independent modules, making it easier to manage.
Correct answer is: Improved maintainability and reusability
Q.21 Which paradigm is most associated with 'map', 'reduce', and 'filter' operations?
Object-Oriented
Functional
Procedural
Event-Driven
Explanation - Functional programming relies on higher-order functions like map, reduce, and filter.
Correct answer is: Functional
Q.22 Which of these is an anti-pattern in programming?
Code reuse
Magic numbers
Encapsulation
Abstraction
Explanation - Magic numbers are unexplained numeric constants in code that harm readability.
Correct answer is: Magic numbers
Q.23 Which of these is NOT a functional programming language?
Haskell
Scala
Erlang
C
Explanation - C is procedural, not functional.
Correct answer is: C
Q.24 The Open/Closed Principle suggests that software entities should be:
Open for modification, closed for extension
Closed for both modification and extension
Open for extension, closed for modification
Always rewritten
Explanation - The Open/Closed Principle states entities should be extendable without altering existing code.
Correct answer is: Open for extension, closed for modification
Q.25 Which of these paradigms is closest to how humans reason with facts and rules?
Procedural
Logic Programming
Functional
Event-Driven
Explanation - Logic programming models reasoning using facts and inference rules, similar to human logic.
Correct answer is: Logic Programming
