1. End-Of-Line Comments That Should Be Ignored by the Compiler Are Denoted Using
Total Page:16
File Type:pdf, Size:1020Kb
CIS 254 - Midterm.
Date: October 14, 2008.
Name:______School ID:______
1. End-of-line comments that should be ignored by the compiler are denoted using a.Two forward slashes ( // ). b.Three forward slashes ( /// ). c.A slash and a star ( /* ). d.A slash and two starts ( /** ).
2. Which of the following cannot cause a syntax error to be reported by the Java compiler? a.Mismatched {} b.Missing */ in a comment c.Missing ; d.Extra blank lines.
3. Which of the following is not a syntax error? a.System.out.println( ‘Hello world!’ ): b.System.out.println( “Hello world!” ); c.System.out.println( “Hello world!” ); d.System.out.println( Hello world! );
4. Which of the following escape sequences represents new-line? a.\n. b.\r. c.\\. d.\c.
5. When method printf requires multiple arguments, the arguments are separated with ______. a.colons (:). b.semicolons (;). c.commas (,). d.periods (.).
6. Which of the following statements is true? C:\> java hello world a. args[1] will be equals to “world” b. args[0] will be equal to “world” c. args will be equal to “world” d. None of the above. 7. What is the value of result after the following Java statements execute? int a, b, c, d, result; a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; a.119 b.51 c.127 d.59
8. A class instance creation expression contains: a. Parentheses. b. The new keyword. c. The name of the class. d. All of the above.
9. A block of code is enclosed by? a. The dot separator. b. Open and close square braces []. c. Open and close curly braces {}. d. Open and close parenthesis (). e. None of the above.
10. Multiple parameters are separated with what symbol? a. The dot separator b. Commas. c. Parentheses. d. Braces.
11. What is the default initial value of a String? a. “” b. “default” c. default d. null
12. Every java program you want to run from the operating system must have? a. private static void main (String[] args).. b. private static void main(). c. public static void main(). d. public static void main (String[] args). 13. A default constructor has how many parameters? a. 0. b. 1. c. 2. d. Variable.
14. What is output by the following Java code segment? int temp; temp = 180;
while ( temp != 80 ) { if ( temp > 90 ) { System.out.print( "This porridge is too hot! " );
// cool down temp = temp – ( temp > 150 ? 100 : 20 ); } // end if else { if ( temp < 70 ) { System.out.print( "This porridge is too cold! ");
// warm up temp = temp + (temp < 50 ? 30 : 20); } // end if } // end else } // end while
if ( temp == 80 ) System.out.println( "This porridge is just right!" );
a.This porridge is too cold! This porridge is just right! b.This porridge is too hot! This porridge is just right! c.This porridge is just right! d.None of the above.
15. A dangling-else can be clarified by using: a.Indentation b.Parentheses () c.Braces {} d.End-of-line comment // 16. Explain the role that the environmental variable CLASSPATH plays in compiling and running java programs.
17. What does the expression x %= 10 do? a.Adds 10 to the value of x, and stores the result in x. b.Divides x by 10 and stores the remainder in x. c.Divides x by 10 and stores the integer result in x. d.None of the above.
18. Which of the following is not a primitive type? a.char. b.float. c.String. d.int.
19. Consider the following two Java code segments:
Segment 1 Segment 2 int i = 0; for ( int i = 0; i <= 20; i++ ) while ( i < 20 ) { { System.out.println( i ); i++; } System.out.println( i ); }
Which of the following statements are true? a.The output from these segments is not the same. b.The scope of the control variable i is different for the two segments. c.Both (a) and (b) are true. d.Neither (a) nor (b) is true.
20. Which of the following will count down from 10 to 1 correctly? a.for ( int j = 10; j <= 1; j++ ) b.for ( int j = 1; j <= 10; j++ ) c.for ( int j = 10; j > 1; j-- ) d.for ( int j = 10; j >= 1; j-- )
21. Which of the following statements about a do…while repetition statement is true? a.The body of a do…while loop is executed only if the terminating condition is true. b.The body of a do…while loop is executed only once. c.The body of a do…while loop is always executed at least once. d.None of the above 22. What must the file name be for class helloWorld?
23. An array of any data type is always passed to a method by. a. Value. b. Copy. c. Reference. d. Global Name. e. None of the above
24. Which of the following statements describes block scope? a.It begins at the opening { of the class declaration and terminates at the closing } b.It limits label scope to only the method in which it is declared. c.It begins at the identifier's declaration and ends at the terminating right brace (}). d.It is valid for one statement only.
25. An overloaded method is one that a.has a different name as another method, but the same parameters. b.has the same name as another method, but different parameters. c.has the same name and parameters as a method defined in another class. d.has the same name and parameters, but a different return type as another method.