MCQs / Computer Science / NSCT: Programming (C++ / Java / Python)
NSCT: Programming (C++ / Java / Python) MCQs — Computer Science (page 6) 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.
126. Calling a method on a null reference in Java throws: NullPointerException ClassCastException StackOverflowError IOException Answer: A) NullPointerException
Explanation: There is no object to call the method on. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
127. What is the output of this Python code? python i = 0 while i < 10: i += 3 print(i) 3 10 12 9 Answer: C) 12
Explanation: Running the code prints 12. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
128. The index of the first element of an array in C++, Java and Python is: 1 It depends on the size 0 −1 Answer: C) 0
Explanation: All three are zero-indexed. Lesson 2.2 · Programming (C++ / Java / Python)
Discuss this question
129. What is the output of this Python code? python print(round(2.5), round(3.5)) 3 3 2 3 2 4 3 4 Answer: C) 2 4
Explanation: Running the code prints 2 4. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
130. Which is a checked exception in Java? ArrayIndexOutOfBoundsException IOException NullPointerException ArithmeticException Answer: B) IOException
Explanation: Checked exceptions must be caught or declared. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
131. Python manages memory mainly through: Manual free() calls Reference counting plus a cyclic garbage collector The stack only Smart pointers Answer: B) Reference counting plus a cyclic garbage collector
Explanation: Objects are freed when no references remain. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
132. The finally block in Java: Runs only when there is an exception Is mandatory with every try Runs only when there is no exception Always executes, whether or not an exception occurs Answer: D) Always executes, whether or not an exception occurs
Explanation: Used to release resources. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
133. A blueprint from which objects are created is a: Method Variable Class Package Answer: C) Class
Explanation: Objects are instances of a class. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
134. The 'this' keyword refers to: The main class The parent class A static method The current object Answer: D) The current object
Explanation: It distinguishes fields from parameters with the same name. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
135. Which C++ feature frees memory automatically when an owner goes out of scope? Raw pointers malloc Smart pointers such as uniqueptr goto Answer: C) Smart pointers such as uniqueptr
Explanation: Smart pointers follow RAII. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
136. Objects created with new in C++ are stored in the: Heap Register Code segment Stack Answer: A) Heap
Explanation: Dynamic allocation uses the heap. Lesson 2.4 · Programming (C++ / Java / Python)
Discuss this question
137. Which is a valid way to declare a constant in Java? let MAX = 10; final int MAX = 10; static MAX = 10; const int MAX = 10; Answer: B) final int MAX = 10;
Explanation: Java uses the final keyword. Lesson 2.1 · Programming (C++ / Java / Python)
Discuss this question
138. What is the output of this Python code? python class Counter: total = 0 def init(self): Counter.total += 1 a = Counter() b = Counter() c = Counter() print(Counter.total) 0 2 1 3 Answer: D) 3
Explanation: Running the code prints 3. Lesson 2.3 · Programming (C++ / Java / Python)
Discuss this question
Previous Page 6 of 6
Practise NSCT: Programming (C++ / Java / Python) MCQs
More Computer Science chapters