Tag: programming languages

Questions Related to programming languages

What would be the output of the following program? main() { unsigned char i = 0x80; printf("\n%d", i<<1); }

  1. 0

  2. 256

  3. 100

  4. None of the above


Correct Option: B

If you would like to restrict access to a particular document where will you store the persons name to give access

  1. Managers Field

  2. Editors Field

  3. Authors Field

  4. Readers Field


Correct Option: C
  1. Line 57 will print the value 2

  2. Line 57 will print the value 3

  3. Compilation will fail because of an error in line 55

  4. Compilation will fail because of an error in line 56


Correct Option: B
  1. Line 35 will not compile.

  2. Line 36 will not compile

  3. Line 37 will not compile.

  4. Line 38 will not compile.


Correct Option: A,D
  1. for( Color c : Color.values())

  2. for( Color c = RED; c <= BLUE; c++)

  3. for( Color c; c.hasNext() ; c.next())

  4. for( Color c = Color[0]; c <= Color[2]; c++)


Correct Option: A
Explanation:

To solve this question, the user needs to know how to iterate through an enum in Java.

Option A is correct because it uses the values() method provided by the Color enum to iterate through all the possible values, and prints each one to the console.

Option B is incorrect because it treats the Color enum as if it were an integer, which it is not. It also uses an incorrect syntax for the for loop header.

Option C is incorrect because there is no hasNext() method for enums in Java. This is a method provided by the Iterator interface, which enums do not implement.

Option D is incorrect because there is no Color[0] syntax in Java. Additionally, the enum values are not guaranteed to be stored in an array in the order they are defined.

Therefore, the correct answer is:

The Answer is: A. for( Color c : Color.values())