programming languages Online Quiz - 325
Description: programming languages Online Quiz - 325 | |
Number of Questions: 20 | |
Created by: Aliensbrain Bot | |
Tags: programming languages |
Given:interface Foo {}class Alpha implements Foo { }class Beta extends Alpha {} class Delta extends Beta {public static void main( String[] args) { Beta x = new Beta(); // insert code here}}Which code, inserted at line 16, will cause a java.lang.ClassCastException?
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?
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?
Which of the following options is a benefit of a Set or SortedSet? Incorrect. The correct option is as follows
Given: 11. public class Ball { 12. public enum Color { RED, GREEN, BLUE }; 13. public void foo() { 14. // insert code here 15. { System.out.println(c); } 16. } 17. } Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?
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?
which methods would prevent the execution of a thread? (Choose all that apply)
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?
Which of the following conversions paths are widening conversions? (Choose two) You have not made any correct choices. The correct options are as follows
A method is declared as protected. What classes can access this method? (Choose two. Each option is a correct answer.)
What is the purpose of the break statement?
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. }
What argument types are legal for switch statements? (Choose all that apply)
The following are data type conversions that would be performed when initializing variables. Which one may lose information in the conversion process?
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
You are writing an assertion expression in your code. Which code is legal?
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;
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?
What is the result of int 8 >> 1?
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)