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

Given the following directory tree, you must enable assertions for everything except for FileTwo. base |firstLevelDirectory |_Foo |_Bar | secLevelDirectory |_FileOne |_FileTwo What command-line code should you use?

    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

You have the following code: public class Java { static double dSyntaxs; public static void main (String [] args) { Java IsItTrue = new Java(); IsItTrue.TrueSyntax(); } public void TrueSyntax() { System.out.println("Its: " + dSyntaxs); } } What would the output be?

    1. Its: 1
    1. Its: 0
    1. Its: true
  1. 4 Its: false

    1. Its: 0.0

Correct Option: E

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

Which of the following conversions paths are widening conversions? (Choose two) You have not made any correct choices. The correct options are as follows

  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

A method is declared as protected. What classes can access this method? (Choose two. Each option is a correct answer.)

    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

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

Which of the following are appropriate ways to use assertions? (Choose all that apply) You have not made any correct choices. The correct options are as follows

  1. 1 public void myMethod(int x) {

  2. 2 private void myMethod(int x) {

  3. 3 switch(z) {

  4. 4 private void anotherMethod() {


Correct Option: B,C
  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

You have declared a single dimensional array of type int using the following code: int [] MyInt = new int [10]; You are attempting to initialize all of the arrays segments with a for loop using the following code: for (int x = 0; x <= 10; x++) { MyInt[x] = x; } What will happen when you attempt to compile the program that contains this code?

    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

What is the result of int 8 >> 1?

    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

The following code throws an exception. public class ContainerClass { public void draw() throws IOException { // additional code to write values to file. system.out.println("This container was drawn and saved to file."); return true; } } What code overrides this method? (Note that Exception itself is a superclass of IOException)

  1. 1 public class Cup extends ContainerClass {

  2. 2 public class Basket extends ContainerClass {

  3. 3 public class Caldron extends ContainerClass {

  4. 4 public class Bag extends ContainerClass {


Correct Option: B
- Hide questions