0% found this document useful (0 votes)
9 views11 pages

Basic Programming Concepts

Uploaded by

kingamaan460
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Basic Programming Concepts

Uploaded by

kingamaan460
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Basic Programming Concepts

1. Which of the following is not a programming language?


a) Python
b) Java
c) HTML
d) C++
Answer: c) HTML

2. What does IDE stand for in programming?


a) Integrated Development Environment
b) Internal Data Execution
c) Interactive Debugging Engine
d) Integrated Design Execution
Answer: a) Integrated Development Environment

3. Which of the following is an example of a high-level programming language?


a) Assembly
b) C
c) Machine Code
d) Binary
Answer: b) C

4. What is the main purpose of a compiler?


a) Execute the program
b) Convert source code into machine code
c) Debug the program
d) Optimize memory usage
Answer: b) Convert source code into machine code

5. Which programming paradigm is Python based on?


a) Procedural
b) Object-Oriented
c) Functional
d) All of the above
Answer: d) All of the above

6. What is the size of an int data type in most modern 64-bit compilers?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes
Answer: b) 4 bytes

7. Which of the following is a valid variable name in Python?


a) 1variable
b) my-variable
c) _myVariable
d) my variable
Answer: c) _myVariable

8. What is the default value of an uninitialized variable in Java?


a) 0
b) null
c) Garbage Value
d) Compiler Error
Answer: d) Compiler Error

9. Which data type is used to store a single character in C?


a) int
b) char
c) string
d) float
Answer: b) char

10. What is the output of sizeof(char) in C?


a) 1
b) 2
c) 4
d) 8
Answer: a) 1
11. Which loop is guaranteed to execute at least once?
a) for loop
b) while loop
c) do-while loop
d) None of the above
Answer: c) do-while loop

12. Which of the following is NOT a valid loop in Python?


a) for
b) while
c) do-while
d) None of the above
Answer: c) do-while

13. Which keyword is used to exit a loop in C?


a) exit
b) break
c) stop
d) return
Answer: b) break

14. What is the output of if(0) in C?


a) True
b) False
c) Error
d) None of the above
Answer: b) False

15. Which of the following statements about switch-case is true?


a) It can handle floating-point numbers
b) The break statement is optional
c) It allows duplicate cases
d) It cannot be nested
Answer: b) The break statement is optional
16. Which of the following is a correct declaration of a function in C?
a) function(int x)
b) int function(int x)
c) int function x()
d) void function x()
Answer: b) int function(int x)

17. What is the default return type of a function in C?


a) int
b) void
c) float
d) char
Answer: a) int

18. Which of the following symbols is used to denote a pointer in C?


a) &
b) *
c) ->
d) %
Answer: b) *

19. What is the output of printf("%p", &x); where x is an integer?


a) Address of x
b) Value of x
c) Size of x
d) None of the above
Answer: a) Address of x

20. Which function is used to dynamically allocate memory in C?


a) malloc()
b) alloc()
c) new()
d) calloc()
Answer: a) malloc()
21. Which of the following is NOT a pillar of OOP?
a) Encapsulation
b) Inheritance
c) Compilation
d) Polymorphism
Answer: c) Compilation

22. Which keyword is used for inheritance in Java?


a) extend
b) implements
c) inherits
d) extends
Answer: d) extends

23. Which function is called automatically when an object is created?


a) Destructor
b) Constructor
c) Copy constructor
d) Finalizer
Answer: b) Constructor

24. Which of the following supports multiple inheritance?


a) Java
b) Python
c) C#
d) JavaScript
Answer: b) Python

25. What is function overloading?


a) Defining multiple functions with the same name but different parameters
b) A function that calls itself
c) A function inside another function
d) A function with a large number of parameters
Answer: a) Defining multiple functions with the same name but different parameters
26. Which data structure follows LIFO?
a) Queue
b) Stack
c) Linked List
d) Array
Answer: b) Stack

27. What is the time complexity of searching in a binary search tree (BST) in the
average case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)

28. Which sorting algorithm has the best average-case time complexity?
a) Bubble Sort
b) Quick Sort
c) Insertion Sort
d) Selection Sort
Answer: b) Quick Sort

29. Which data structure is best for implementing a priority queue?


a) Stack
b) Queue
c) Heap
d) Linked List
Answer: c) Heap

30. Which traversal technique follows Root-Left-Right?


a) Inorder
b) Preorder
c) Postorder
d) Level Order
Answer: b) Preorder
31. Which feature of OOP allows code reusability?
a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism
Answer: c) Inheritance

32. Which access modifier allows a variable to be accessed within the same class and
derived classes?
a) private
b) protected
c) public
d) default
Answer: b) protected

33. Which of the following best defines encapsulation?


a) Wrapping data and methods into a single unit
b) Hiding implementation details from the user
c) Allowing multiple objects to share the same attributes
d) Restricting the visibility of variables
Answer: a) Wrapping data and methods into a single unit

34. Which principle of OOP promotes hiding implementation details?


a) Polymorphism
b) Abstraction
c) Inheritance
d) Overloading
Answer: b) Abstraction

35. Which of the following is NOT an advantage of OOP?


a) Code reusability
b) Improved maintainability
c) Faster execution speed
d) Enhanced security
Answer: c) Faster execution speed
36. Which keyword is used to define a class in Java?
a) object
b) struct
c) class
d) define
Answer: c) class

37. What happens when an object is created using the new keyword?
a) Memory is allocated for the object
b) The constructor of the class is called
c) A reference to the object is returned
d) All of the above
Answer: d) All of the above

38. Which of the following statements about objects is true?


a) An object must always be created using new
b) Objects contain only data and no methods
c) Objects are instances of a class
d) A class cannot have multiple objects
Answer: c) Objects are instances of a class

39. Which function is automatically invoked when an object is created?


a) Destructor
b) Constructor
c) finalize()
d) toString()
Answer: b) Constructor

40. Which keyword in C++ is used to create an object dynamically?


a) new
b) malloc
c) alloc
d) dynamic
Answer: a) new
41. What is inheritance in OOP?
a) A process of creating new classes from existing classes
b) A function that calls itself
c) A way to define multiple classes
d) A method to prevent data redundancy
Answer: a) A process of creating new classes from existing classes

42. Which type of inheritance is supported by Java?


a) Single Inheritance
b) Multiple Inheritance (via Interfaces)
c) Multilevel Inheritance
d) All of the above
Answer: d) All of the above

43. Which keyword is used to inherit a class in C++?


a) extends
b) inherits
c) derived
d) : (colon)
Answer: d) : (colon)

44. Which OOP principle allows different classes to have methods with the same
name but different implementations?
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Association
Answer: c) Polymorphism

45. Which type of polymorphism is resolved at compile time?


a) Function Overloading
b) Operator Overloading
c) Method Overloading
d) All of the above
Answer: d) All of the above
46. What is an exception in programming?
a) A syntax error
b) A runtime error
c) A logical error
d) An infinite loop
Answer: b) A runtime error

47. Which keyword is used to handle exceptions in Java?


a) error
b) exception
c) try-catch
d) throw-catch
Answer: c) try-catch

48. What does the finally block do in Java?


a) It executes only if an exception occurs
b) It executes only if no exception occurs
c) It always executes, regardless of exceptions
d) It stops execution of the program
Answer: c) It always executes, regardless of exceptions

49. Which exception is thrown when an array index is out of bounds in Java?
a) NullPointerException
b) IndexOutOfBoundsException
c) IllegalArgumentException
d) ArithmeticException
Answer: b) IndexOutOfBoundsException

50. Which function is used to manually throw an exception in Java?


a) throw
b) throws
c) catch
d) raise
Answer: a) throw

51. What is the superclass of all exceptions in Java?


a) Error
b) Throwable
c) RuntimeException
d) Exception
Answer: b) Throwable

52. Which type of exceptions must be handled using a try-catch block or declared
using throws?
a) Checked exceptions
b) Unchecked exceptions
c) Runtime exceptions
d) Logical exceptions
Answer: a) Checked exceptions

53. Which keyword is used in Java to declare an exception in a method signature?


a) throws
b) throw
c) try
d) exception
Answer: a) throws

54. Which exception is thrown when a method receives an invalid argument?


a) IllegalArgumentException
b) IOException
c) ArithmeticException
d) NullPointerException
Answer: a) IllegalArgumentException

55. Which of the following statements about exception handling is true?


a) An exception must always be handled using try-catch
b) Multiple exceptions can be caught using multiple catch blocks
c) The finally block only executes when an exception is thrown
d) Java does not support exception handling
Answer: b) Multiple exceptions can be caught using multiple catch blocks

You might also like