101. What is the output of this Python code? python print('5' 3)
- 5 5 5
- 15
- 555
- Error
Answer: C) 555
Explanation: Running the code prints 555. Lesson 2.1 · 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: C) 555
Explanation: Running the code prints 555. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) 40
Explanation: Negative indices count from the end. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) 5
Explanation: Running the code prints 5. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) -4
Explanation: Floor division rounds down toward negative infinity. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: D) [0, 1, 4, 9]
Explanation: Running the code prints [0, 1, 4, 9]. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) They can contain abstract and default methods
Explanation: Default methods have a body; interfaces cannot be instantiated. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: B) 2 bytes (Unicode)
Explanation: Java chars are 16-bit UTF-16 code units. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) raise
Explanation: Java uses throw; Python uses raise. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: D) banana
Explanation: Running the code prints banana. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: D) Local variables
Explanation: They exist only during the function call. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) bad
Explanation: Running the code prints bad. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: B) Method overriding
Explanation: Overriding gives run-time polymorphism. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: A) 12
Explanation: Running the code prints 12. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: A) 512
Explanation: Running the code prints 512. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: A) 15
Explanation: Running the code prints 15. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) 3
Explanation: Both operands are int, so integer division truncates. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: B) boolean
Explanation: Java uses boolean with values true and false. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: A) Fall-through to the next case
Explanation: Execution continues into the following case. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) Allocated memory is never freed
Explanation: Memory stays reserved but unusable. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: B) "3030"
Explanation: Evaluation is left to right: 10 + 20 = 30, then 30 + "30" = "3030". Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) The value of x
Explanation: dereferences the pointer. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: D) Hi Ali
Explanation: Running the code prints Hi Ali. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: B) Method overriding
Explanation: The JVM picks the method based on the actual object type. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: B) 9 a
Explanation: Running the code prints 9 a. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: C) private
Explanation: private members are visible only inside the class. Lesson 2.3 · Programming (C++ / Java / Python)
Practise NSCT: Programming (C++ / Java / Python) MCQs