Question
Consider a Java method printList(Node head) for a singly
linked list. class Node { Â Â int data; Â Â Node next; Â Â Node(int d) { data = d; next = null; } } public void printList(Node head) { Â Â Node current = head; Â Â while (current != null) { Â Â Â Â System.out.print(current.data + " "); Â Â Â Â current = current.next; Â Â } Â Â // Bug: What if the list is empty? Â Â System.out.println(current.data); // Line X } If printList(null) is called (an empty list), what will happen at Line X?Solution
• Dry Run: o Call printList(null):  head is null.  Node current = head; sets current to null.  The while (current != null) condition (null != null) is false. The loop is skipped entirely.  Execution proceeds to System.out.println(current.data); (Line X).  At this point, current is null. Attempting to access current.data on a null reference triggers a NullPointerException. • Why Correct Answer (B): A NullPointerException will be thrown. o This directly follows from the dry run. The code attempts to dereference a null pointer after the loop.
Untouchability is abolished and it’ s practice in any form is abolished as per which Articla of the Constitution?
Section 13 of the Chhattisgarh Excise Act related to:
What must a mediated settlement agreement include under The Mediation Act, 2023?
What is the legal status of a contract where the performance of the agreed-upon act, after the contract is made, becomes impossible or unlawful due to a...
Who has exclusive right to carry life insurance business in India as per LIC Act?Â
During the arbitral proceedings, interim measures can be ordered by Arbitral Tribunal:
For refreshing memory a witness may refer a writing_____.
Confession is defined under which section of Indian Evidence Act?
The prohibitory order passed under Section 144 of the Code of Criminal Procedure shall not remain in force for more than ____ from making thereof.Â
Article 244(2) of the Constitution empowers the Governor to make regulations for certain areas. Which of these is TRUE about those regulations?