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:

  1. Auto-save
  2. Syntax highlighting
  3. Step-through debugging
  4. 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:

  1. A type of variable
  2. A lightweight unit of execution within a process
  3. A separate program
  4. 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:

  1. A template class
  2. An abstract class
  3. A final class
  4. 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))

  1. 3
  2. Error
  3. 4
  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='')

  1. F
  2. Error
  3. I
  4. 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])

  1. True True True
  2. True True False
  3. True False False
  4. 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))

  1. False False
  2. False True
  3. True True
  4. 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?

  1. tuple
  2. list
  3. dict
  4. 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:

  1. Register variable
  2. Parameter
  3. Local variable
  4. 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?

  1. 4
  2. 3
  3. 5
  4. 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:

  1. Dangling pointer
  2. Smart pointer
  3. Void pointer
  4. 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:

  1. Bytecode run by the JVM
  2. Machine code only
  3. HTML
  4. 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. [1]
  2. [2]
  3. [1, 2]
  4. 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())

  1. A
  2. BA
  3. AB
  4. 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. 1 2 3
  2. 0 1 2
  3. 0 1 2 3
  4. 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:

  1. Stack overflow
  2. Memory leak
  3. Syntax error
  4. 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?

  1. The percentage
  2. The quotient
  3. The power
  4. 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?

  1. 2 bytes
  2. 8 bytes
  3. It depends on the computer
  4. 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?

  1. <string
  2. <conio
  3. <stdio
  4. <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)

  1. 4
  2. 3
  3. 7
  4. 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')

  1. A B
  2. B
  3. C
  4. 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:

  1. Memory leak in the heap
  2. Heap overflow
  3. Stack overflow
  4. 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())

  1. T
  2. FT
  3. TF
  4. 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)))

  1. 5000
  2. 10100
  3. 5050
  4. 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:

  1. Polymorphism
  2. Composition (aggregation)
  3. Inheritance
  4. 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