MCQs / Computer Science / NSCT: Programming (C++ / Java / Python)
NSCT: Programming (C++ / Java / Python) MCQs — Computer Science (page 3) 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.
51. An IDE feature that lets you run code one line at a time is: Auto-save Syntax highlighting Step-through debugging Code folding Answer: C) Step-through debugging
Explanation: Stepping shows exactly where values change. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
52. A thread is: A type of variable A lightweight unit of execution within a process A separate program A network cable Answer: B) A lightweight unit of execution within a process
Explanation: Threads share the process's memory. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
53. In C++, a class with at least one pure virtual function (virtual void f() = 0;) is: A template class An abstract class A final class A friend class Answer: B) An abstract class
Explanation: It cannot be instantiated. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
54. What is the output of this Python code? python a = [3, 1, 2] b = a b.append(4) print(len(a)) 3 Error 4 1 Answer: C) 4
Explanation: Running the code prints 4. Lesson 2.2 · Programming (C++ / Java / Python)
Discuss this question
55. What is the output of this Python code? python try: x = [1, 2][5] except IndexError: print('I', end='') finally: print('F', end='') F Error I IF Answer: D) IF
Explanation: Running the code prints IF. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
56. What is the output of this Python code? python a = [1, 2] b = a print(a is b, a == [1, 2], a is [1, 2]) True True True True True False True False False False True False Answer: B) True True False
Explanation: Running the code prints True True False. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
57. What is the output of this Python code? python print(3 == 3.0, type(3) == type(3.0)) False False False True True True True False Answer: D) True False
Explanation: Running the code prints True False. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
58. Which Python data type is immutable? tuple list dict set Answer: A) tuple
Explanation: Tuples cannot be changed after creation. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
59. A variable declared outside all functions and usable everywhere in the file is a: Register variable Parameter Local variable Global variable Answer: D) Global variable
Explanation: Global scope covers the whole module. Lesson 2.2 · Programming (C++ / Java / Python)
Discuss this question
60. What does len("NSCT") return in Python? 4 3 5 Error Answer: A) 4
Explanation: There are four characters. Lesson 2.2 · Programming (C++ / Java / Python)
Discuss this question
61. A pointer that still refers to memory that has already been freed is a: Dangling pointer Smart pointer Void pointer Null pointer Answer: A) Dangling pointer
Explanation: Using it causes undefined behaviour. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
62. Java source code is compiled into: Bytecode run by the JVM Machine code only HTML Python code Answer: A) Bytecode run by the JVM
Explanation: Bytecode is platform independent. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
63. What is printed? python def add(item, box=[]): box.append(item) return box add(1) print(add(2)) [1] [2] [1, 2] Error Answer: C) [1, 2]
Explanation: The default list is created once and shared between calls. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
64. What is the output of this Python code? python class A: def hi(self): return 'A' class B(A): def hi(self): return super().hi() + 'B' print(B().hi()) A BA AB B Answer: C) AB
Explanation: Running the code prints AB. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
65. What is the output of this Python code? python for i in range(5): if i == 3: break print(i, end=' ') 1 2 3 0 1 2 0 1 2 3 0 1 2 3 4 Answer: B) 0 1 2
Explanation: Running the code prints 0 1 2. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
66. Two threads increment the same counter without synchronisation. The final value may be wrong because of a: Stack overflow Memory leak Syntax error Race condition Answer: D) Race condition
Explanation: Interleaved read-modify-write steps lose updates. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
67. What does the % operator return? The percentage The quotient The power The remainder of a division Answer: D) The remainder of a division
Explanation: 17 % 5 = 2. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
68. What is the size of an int in Java? 2 bytes 8 bytes It depends on the computer 4 bytes Answer: D) 4 bytes
Explanation: Java fixes int at 32 bits. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
69. In C++, which header is needed for std::cout? <string <conio <stdio <iostream Answer: D) <iostream
Explanation: cout is declared in iostream. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
70. What is the output of this Python code? python print(17 % 5 2) 4 3 7 1 Answer: A) 4
Explanation: Running the code prints 4. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
71. What is the output of this Python code? python x = 7 if x 5 and x < 10: print('A') elif x 6: print('B') else: print('C') A B B C A Answer: D) A
Explanation: Running the code prints A. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
72. Very deep recursion without a base case causes: Memory leak in the heap Heap overflow Stack overflow Syntax error Answer: C) Stack overflow
Explanation: Each call adds a frame to the call stack. Lesson 2.2 · Programming (C++ / Java / Python)
Discuss this question
73. What is the output of this Python code? python def f(): try: return 'T' finally: print('F', end='') print(f()) T FT TF F Answer: B) FT
Explanation: Running the code prints FT. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
74. What is the output of this Python code? python print(sum(range(1, 101))) 5000 10100 5050 100 Answer: C) 5050
Explanation: Running the code prints 5050. Lesson 2.5 · Programming (C++ / Java / Python)
Discuss this question
75. "A Car has an Engine" is an example of: Polymorphism Composition (aggregation) Inheritance Overloading Answer: B) Composition (aggregation)
Explanation: A has-a relationship. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
Previous Page 3 of 6 Next
Practise NSCT: Programming (C++ / Java / Python) MCQs
More Computer Science chapters