Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

public class Probe70
{
    public static void main(String[] args) throws Exception
    {
        String s = "\u0041BC";
        System.out.println(s + " " + s.length());
    }
}

  • A.The program prints \u0041BC 8
  • B.ABC 3
  • C.The program prints u0041BC 7
  • D.Compilation fails.

Answer: B

A Unicode escape is processed by the compiler before the program is even parsed, so the source holds the single character A followed by BC. The string is therefore ABC with a length of 3. The escape never survives as text.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.