Multiple choice technology programming languages

package io; import java.io.*; public class TestFile { public static void main(String[] args) { File file = new File("test_file.txt"); System.out.print(" Fle Name = " + file.getName()); file.delete(); file.renameTo(new File("test_file2.txt")); System.out.print(" Fle Name = " + file.getName()); } }

  1. Null pointer Exception

  2. Fle Name = test_file.txt Fle Name = test_file.txt

  3. Compiler Error

  4. Fle Name = test_file.txt Fle Name = test_file2.txt

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The File object maintains its reference regardless of file system state. file.getName() returns 'test_file.txt' initially. After file.delete(), the file is removed but the File object still holds the original name. The renameTo() operation fails (returns false) because the file was already deleted, so getName() still returns 'test_file.txt'. The File object's state doesn't automatically sync with the filesystem.