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

Discussion

What will be the output of the program ?

public class Test 
{
    public static void main(String [] args) 
    {
        signed int x = 10;
        for (int y=0; y<5; y++, x--) 
        {
            System.out.print(x + ", ");
        }
    }
}

  • A.10, 9, 8, 7, 6,
  • B.9, 8, 7, 6, 5,
  • C.Compilation fails.
  • D.An exception is thrown at runtime.

Answer: C

Correct answer: Compilation fails.

Java has no signed keyword. Its integral types are signed by definition - there is no unsigned counterpart to declare against - so the word is not part of the language and signed int x = 10; is rejected. It is a C and C++ construct, and the same applies to unsigned. Nothing runs, so neither of the printed sequences arises.

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

Post your comment

Please log in or register to post a comment.