76. What is the output of this Python code? python a = [3, 1, 2] b = a.copy() b.append(4) print(len(a))
- 3
- Error
- 4
- 1
Answer: A) 3
Explanation: Running the code prints 3. Lesson 2.2 · Programming (C++ / Java / Python)
MCQs / Computer Science / NSCT: Programming (C++ / Java / Python)
138 multiple-choice questions on NSCT: Programming (C++ / Java / Python) from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.
Answer: A) 3
Explanation: Running the code prints 3. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) x = 6, y = 6
Explanation: Pre-increment increases x first, then assigns. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: B) Implementing multiple interfaces
Explanation: A class may implement any number of interfaces. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: B) Java
Explanation: The JVM runs the same bytecode on any platform. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: D) 2 1
Explanation: Running the code prints 2 1. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: B) Dog's speak()
Explanation: Dynamic dispatch uses the actual object type. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: A) 3.5
Explanation: The / operator always gives a float in Python 3. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: B) 9 32
Explanation: Running the code prints 9 32. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) "olleh"
Explanation: A step of −1 reverses the string. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) Is undefined behaviour
Explanation: C++ does not check bounds for raw arrays. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: B) ACD
Explanation: B is skipped when the exception is thrown; catch and finally run. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: B) 8
Explanation: Running the code prints 8. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: B) Putting repeated logic in one reusable function
Explanation: Duplication makes maintenance harder. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: C) A String object's characters cannot be changed after creation
Explanation: Methods like toUpperCase() return a new String. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) The diamond problem
Explanation: Ambiguity arises when two parents have the same method. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: D) [1, 3, 4] [4, 3, 1]
Explanation: Running the code prints [1, 3, 4] [4, 3, 1]. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) A special method called when an object is created
Explanation: It initialises the new object. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: C) Garbage collector
Explanation: The JVM's garbage collector frees heap memory. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: D) Refactoring
Explanation: Refactoring keeps functionality the same. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: B) 10
Explanation: Running the code prints 10. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) True False
Explanation: Running the code prints True False. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: D) Data Science
Explanation: Running the code prints Data Science. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) False True
Explanation: Running the code prints False True. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) Method overloading
Explanation: Overloading is resolved at compile time. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) (1, 2, 3, 1, 2, 3)
Explanation: Running the code prints (1, 2, 3, 1, 2, 3). Lesson 2.2 · Programming (C++ / Java / Python)
Practise NSCT: Programming (C++ / Java / Python) MCQs