0

programming languages Online Quiz - 325

Description: programming languages Online Quiz - 325
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
    1. java -ea -da:base.firstLevelDirectory.secLevelDirectory.FileTwo
    1. java -ea:base.firstLevelDirectory.secLevelDirectory.FileTwo -da
    1. java -ea:base... -da:base.firstLevelDirectory.secLevelDirectory...
    1. java -enableassertions -disableassertions:base.FileTwo

Correct Option: A

You are considering four different "if" statements for the following code: public class IsItSame { public static void main(String [] args ) { int TheAnswer = 0; IsItSame x = new IsItSame(); Object y = x; IsItSame z = new IsItSame(); if (z == x) TheAnswer = 0; if (y == x) TheAnswer = 1; if (y == z) TheAnswer = 2; if (y.equals(z) ) TheAnswer = 3: if (x.equals(z) ) TheAnswer = 4; if (z.equals(y) ) TheAnswer = 5; System.out.printIn("The answer is " + TheAnswer); } } What will be printed out once the code is compiled and executed?

    1. The answer is 0
    1. The answer is 1
    1. The answer is 2
    1. The answer is 3
    1. The answer is 4

Correct Option: B
  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++)

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


Correct Option: A

which methods would prevent the execution of a thread? (Choose all that apply)

    1. sleep()
    1. yield()
    1. run()
    1. join()

Correct Option: A,B,D

Given: 10. public class Fabric 11. public enum Color { 12. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 13. private final int rgb; 14. Color( int rgb) { this.rgb = rgb; } 15. public int getRGB() { return rgb; } 16. }; 17. public static void main( String[] argv) { 18. // insert code here 19. } 20. } Which two code fragments, inserted independently at line 18, allow the Fabric class to compile?

  1. Color skyColor = BLUE;

  2. Color treeColor = Color.GREEN;

  3. Color purple = new Color( 0xff00ff);

  4. if( RED.getRGB() < BLUE.getRGB() ) {}

  5. Color purple = Color.BLUE + Color.RED;

  6. if( Color.RED.ordinal() < Color.BLUE.ordinal() ) {}


Correct Option: B,F
  1. 1From a int to a short

  2. 2From a char to an int

  3. 3From a short to an int

  4. 4From a double to a float

  5. 5From a float to a long


Correct Option: B,C
    1. Classes in the same package
    1. All classes
    1. Only the class within the package that defined the method
    1. Classes that inherit access

Correct Option: A,D

What is the purpose of the break statement?

    1. It jumps out of the loop back to the calling method.
    1. It jumps out of the loop to the next statement after the loop.
    1. It stops the execution of the program and of the virtual machine.
    1. It stops the innermost iteration and continues with the next iteration of the loop.

Correct Option: B

Between which two lines should you insert a break or a continue statement to print the message "Please close the door. I feel a draft. Thank you"? (Line numbers are included only for clarity's sake) 1. String door="open"; 2. boolean draft=false; 3. boolean shivers=false; 4. while (door=="open") { 5. draft=true; 6. System.out.println("Please close the door."); 7. if (draft) { 8. shivers=true; 9. System.out.println("I feel a draft."); 10. door="close"; 11. if (shivers) { 12. System.out.println("I'm shivering."); 13. } 14. } 15. } 16. if (door=="close") { 17. System.out.println("Thank you"); 18. shivers=false; 19. }

    1. Replace lines 7 to 14 with a break statement.
    1. Replace lines 7 to 14 with a continue statement.
    1. Replace line 12 with a continue statement.
    1. Insert a break statement between lines 16 and 17.

Correct Option: C

What argument types are legal for switch statements? (Choose all that apply)

    1. char
    1. byte
    1. short
    1. int
    1. boolean

Correct Option: A,B,C,D

The following are data type conversions that would be performed when initializing variables. Which one may lose information in the conversion process?

    1. From an int to a long
    1. From a byte to an int
    1. From a short to a byte
    1. From an int to a double
  1. 5) All of the above


Correct Option: E
  1. 1 int z = 0;

  2. 2 assert (z = 9);

  3. 3 assert (x ==5);

  4. 4 int z = 0;

  5. 5 boolean x = true;


Correct Option: C

you assign a value to the primitive variables x and y as indicated below. Which declaration for z must be used for this code to properly compile? byte x = 3; byte y = 2; // insert declaration for z here z = x + y;

    1. byte z;
    1. int z;
    1. char z
    1. None of these options are correct

Correct Option: B
    1. The program will run successfully with no errors or warnings.
    1. The program will halt with a runtime exception.
    1. The program will halt with a compiler error.
    1. The program will run successfully with no errors but a warning will be generated.

Correct Option: B
    1. 0000 0000 0000 0000 0000 0000 0000 0100
    1. 0000 0000 0000 0000 0000 0000 0000 1000
    1. 0000 0000 0000 0000 0000 0000 0001 0000
    1. 0000 0000 0000 0000 0000 0000 0000 0111
    1. 0000 0000 0000 0000 0000 0000 0000 1001

Correct Option: A
- Hide questions