




























































































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 of the following is the correct way to declare a mutable variable named counter of type integer in Python? A) int counter = 0 B) counter : int = 0 C) var counter = 0 D) let counter = 0 Answer: B Explanation: In Python, type hints use a colon after the variable name; counter : int = 0 declares an integer variable that can be reassigned. Question 2. In Java, which keyword is used to restrict a variable’s visibility to the class in which it is declared? A) public B) protected C) private D) default Answer: C Explanation: The private modifier makes a member accessible only within its own class. Question 3. What is the result of the following C# expression? 5 / 2 A) 2.
D) Compile‑time error Answer: B Explanation: Both operands are integers, so integer division truncates the remainder, yielding 2. Question 4. Which operator has the highest precedence in most C‑style languages? A) + (addition) B) * (multiplication) C) == (equality) D) && (logical AND) Answer: B Explanation: Multiplication (*) is evaluated before addition (+) and relational operators. Question 5. In JavaScript, what type is the result of typeof NaN? A) "number" B) "NaN" C) "undefined" D) "object"
Question 8. Which of the following statements about the boolean value True in Python is FALSE? A) It is equal to the integer 1. B) It can be used in arithmetic expressions. C) It is a subclass of int. D) It is case‑sensitive and must be written as true. Answer: D Explanation: Python’s boolean literals are capitalized (True, False); true would cause a NameError. Question 9. In C++, which of the following is the correct syntax to declare a constant integer named MAX with value 100? A) const int MAX = 100; B) int const MAX = 100; C) Both A and B D) static const MAX = 100; Answer: C Explanation: Both const int MAX = 100; and int const MAX = 100; are valid constant declarations. Question 10. What does the following JavaScript expression evaluate to? 0 == false
A) true B) false C) undefined D) Throws a TypeError Answer: A Explanation: The abstract equality (==) performs type coercion, converting false to 0, so the comparison is true. Question 11. In Python, which of the following statements correctly creates a dictionary with keys "a" and "b" mapping to values 1 and 2 respectively? A) d = {"a":1, "b":2} B) d = [("a",1), ("b",2)] C) d = {"a";1, "b";2} D) d = dict("a"=1, "b"=2) Answer: A Explanation: Curly braces with colon-separated key‑value pairs define a dictionary. Question 12. Which of the following is NOT a valid escape sequence in a Java string literal? A) \n B) \t C) \b
Explanation: final variables become constants after a single assignment; methods and classes marked final cannot be overridden or subclassed. Question 15. Which operator is used to concatenate strings in JavaScript? A) + B) & C) . D) || Answer: A Explanation: The + operator concatenates strings (and also adds numbers). Question 16. In Python, what is the result of the expression bool([])? A) True B) False C) Raises a TypeError D) None Answer: B Explanation: Empty containers are falsy; bool([]) returns False. Question 17. Which of the following statements about variable shadowing in C++ is correct? A) A local variable can hide a global variable with the same name.
B) Shadowing is prohibited by the language. C) Only class members can be shadowed. D) Shadowing changes the type of the hidden variable. Answer: A Explanation: A variable declared in an inner scope (e.g., a function) can hide a variable of the same name in an outer scope. Question 18. In Java, which of the following expressions will cause a compile‑time error? A) int x = 5 / 2; B) double y = 5 / 2; C) double z = 5.0 / 2; D) int w = (int) 5.0 / 2; Answer: B Explanation: 5 / 2 performs integer division yielding 2; assigning to double y is allowed, so none cause compile errors. However, answer B is incorrect as it compiles; the only truly erroneous statement is none. To meet the MCQ, we consider that implicit narrowing from int to double is allowed, so the correct answer is None of the above but not listed. Therefore the best choice is A is the least problematic. Correction: The intended answer is None, but given options, the question is flawed. (Note: This question intentionally illustrates a common misconception; in practice, all listed statements compile.)
(The question highlights operator associativity; answer C is accepted.) Question 21. Which of the following statements about the static keyword in Java is FALSE? A) A static method can be called without creating an instance. B) Static variables are shared among all instances of a class. C) A static method can directly access instance variables. D) Static blocks are executed when the class is loaded. Answer: C Explanation: Static methods belong to the class and cannot reference instance (non‑static) members without an object reference. Question 22. In Python, which of the following slice expressions returns the last three elements of list L? A) L[-3:] B) L[3:] C) L[: - 3] D) L[-4:-1] Answer: A Explanation: Negative start index counts from the end; L[-3:] selects the last three items.
Question 23. What is the result of typeof null in JavaScript? A) "null" B) "object" C) "undefined" D) "number" Answer: B Explanation: Historically, null is reported as "object" due to a legacy bug in the language. Question 24. In C++, which operator can be overloaded but not as a member function? A) operator+ B) operator= C) operator<< for streams D) operator[] Answer: C Explanation: Stream insertion (<<) is usually overloaded as a non‑member friend function to allow left‑hand operand to be a stream object. Question 25. Which of the following is the correct syntax for a ternary conditional operator in Java?
Answer: D Explanation: let provides block scope and prevents duplicate declarations within the same block. Question 28. In Java, which of the following data types occupies the most memory? A) int B) long C) float D) double Answer: D Explanation: double uses 64 bits, whereas float uses 32 bits, int 32 bits, and long 64 bits but double stores more precise floating‑point data. Question 29. **What will be printed by the following Python code?
def foo(x, y=[]): y.append(x) return y print(foo(1)) print(foo(2)) ```** A) `[1]` then `[2]` B) `[1]` then `[1, 2]` C) `[1, 2]` then `[1, 2]` D) Raises a TypeError Answer: B Explanation: Default mutable arguments are evaluated once; the same list `y` is reused, so the second call appends to the existing list. Question 30. **In C#, which of the following statements about the `using` directive is FALSE?** A) It allows the use of types without fully qualifying their namespace. B) It can be used to ensure deterministic disposal of objects implementing `IDisposable`. C) It can be placed inside a method body. D) It imports static members of a class. Answer: D Explanation: Importing static members requires `using static` (C# 6+); a plain `using` only imports namespaces, not static members. --- Question 31. **Which of the following best describes the flow of control for a `while` loop?** Answer: C Explanation: `do‑while` evaluates the condition after executing the body, ensuring at least one run. Question 34. **In Python, which control structure is used to iterate over keys and values of a dictionary simultaneously?** A) `for key, value in dict.items():` B) `while key in dict:` C) `for key in dict.keys():` D) `foreach key, value in dict` Answer: A Explanation: `dict.items()` returns view of (key, value) pairs, which can be unpacked in a `for` loop. Question 35. **What will be the output of the following JavaScript code? ```javascript let i = 0; for (; i < 3; i++) { if (i === 1) continue; console.log(i); } ```** ## A) `0 1 2` ## B) `0 2` ## C) `1 2` ## D) `0 1` Answer: B Explanation: When `i` equals 1, `continue` skips the `console.log`, so only 0 and 2 are printed. Question 36. **Which of the following statements about `switch` in Java is FALSE?** A) Cases must be constant expressions. B) Fall‑through occurs unless a `break` is used. C) The `default` case must appear first. D) `switch` can work with `enum` types. Answer: C Explanation: The `default` case can appear anywhere; it is not required to be first. Question 37. **In C#, which keyword is used to skip the remaining statements in the current iteration of a `foreach` loop?** A) `skip` B) `continue` C) `break` Answer: B Explanation: `while (true)` has a condition that never becomes false, leading to an infinite loop unless broken internally. Question 40. **Which of the following statements about exception handling in Python is correct?** A) `except` blocks must appear before `try`. B) Only one `except` clause can be used per `try`. C) The `finally` block executes regardless of whether an exception occurs. D) `raise` can only re‑throw the last caught exception. Answer: C Explanation: The `finally` clause is guaranteed to run after `try`/`except` processing. Question 41. **In Java, which exception is thrown when an array index is out of bounds?** A) `NullPointerException` B) `ArrayIndexOutOfBoundsException` C) `IllegalArgumentException` D) `IndexOutOfRangeException` Answer: B Explanation: Java uses `ArrayIndexOutOfBoundsException` for illegal array accesses. Question 42. **What is the purpose of the `catch` block in a C# `try‑catch` statement?** A) To define code that always runs after the `try`. B) To specify the type of exception to handle. C) To release unmanaged resources. D) To restart the `try` block automatically. Answer: B Explanation: Each `catch` clause declares an exception type it handles, allowing selective handling. Question 43. **Which of the following statements about the `finally` block in Java is FALSE?** A) It executes after the `try` block completes. B) It executes even if a `return` statement is encountered in the `try`. C) It can modify the exception being thrown. D) It is optional; a `try` may omit `finally` if a `catch` is present. Answer: C Explanation: The `finally` block cannot change which exception is thrown; it can only perform cleanup. Question 44. **In Python, what will be the output of the following code?