quiz example

191 downloads 326 Views 140KB Size Report
Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is. A) java ...
Exam Name___________________________________

MULTIPLE CHOICE.  Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java Test C) javac Test D) javac Test.java E) JAVAC Test.java

1)

2) Java was developed by ________. A) IBM B) Microsoft C) Sun Microsystems D) Oracle E) Cisco Systems

2)

3) Which of the following are the reserved words? (Choose all that apply.) A) class B) public C) void

3) D) static

4) The ________ method displays a message dialog box. (Choose all that apply.) A) JOptionPane.showMessageDialog(null, ʺWelcome to Java!ʺ, ʺExample 1.2 Outputʺ, JOptionPane.INFORMATION_MESSAGE); B) JOptionPane.displayMessage(null, ʺWelcome to Java!ʺ, ʺExample 1.2 Outputʺ, JOptionPane.INFORMATION_MESSAGE); C) JOptionPane.showMessageDialog(null, ʺWelcome to Java!ʺ); D) JOptionPane.displayMessageDialog(null, ʺWelcome to Java!ʺ, ʺExample 1.2 Outputʺ, JOptionPane.INFORMATION_MESSAGE); E) JOptionPane.showMessage(null, ʺWelcome to Java!ʺ, ʺExample 1.2 Outputʺ, JOptionPane.INFORMATION_MESSAGE);

4)

5) ________ is an operating system. A) Windows XP B) Ada C) C++ D) Visual Basic E) Java

5)

6) Every statement in Java ends with ________. A) a period (.) B) an asterisk (*) 7) ________is interpreted. A) Pascal B) Ada

6) C) a semicolon (;)

D) a comma (,) 7)

C) C++

D) C

1

E) Java

8) Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.) A) System.out.print(ʹWelcome to Javaʹ); B) System.out.println(ʹWelcome to Javaʹ); C) System.out.println(ʺWelcome to Javaʺ); D) System.println(ʹWelcome to Javaʹ); E) System.out.print(ʺWelcome to Javaʺ);

8)

9) To use JOptionPane in your program, you may import it using: (Choose all that apply.) A) import javax.*.JOptionPane; B) import javax.swing.JOptionPane; C) import javax.*; D) import javax.swing.*;

9)

10) ________is Architecture-Neutral. A) Ada B) Java

10) C) Pascal

D) C

E) C++

11) The extension name of a Java source code file is A) .exe B) .class

C) .obj

D) .java

11)

12) A block is enclosed inside ________. A) parentheses B) braces

C) quotes

D) brackets

12)

13) The speed of the CPU is measured in ________. (Choose all that apply.) A) gigabytes B) gigahertz C) megabytes

13) D) megahertz 14)

14) ________is an object-oriented programming language. (Choose all that apply.) B) Pascal C) Ada D) C++ A) Java 15) Math.pow(2, 3) returns ________. A)  9.0 B)  9

E) C 15)

C) 8.0

D)  8

16) The ________ method parses a string s to an int value. A) integer.parseInteger(s); B) integer.parseInt(s); C) Integer.parseInt(s); D) Integer.parseInteger(s);

16)

17) The expression ʺJava ʺ + 1 + 2 + 3 evaluates to ________. A) Java 123 B) Java123 C) java 123 D) Java6 E) Illegal expression

17)

18) Which of the following is the correct expression of character 4? A) 4 B) ʹ4ʹ C) ʹ\0004ʹ

D) ʺ4ʺ

18)

19) What is the printout of System.out.println(ʹzʹ - ʹaʹ)? A) z B) a

D) 26

19) C) 25

2

20) Analyze the following code.

20)

import javax.swing.*; public class ShowErrors {   public static void main(String[ ] args) {     int i;     int j;     String s = JOptionPane.showInputDialog(null,        ʺEnter an integerʺ, ʺInputʺ,        JOptionPane.QUESTION_MESSAGE);     j = Integer.parseInt(s);     i = (i + 4);   } } A) The program cannot compile because i does not have an initial value when it is used in i  = i + 4; B) The program cannot compile because j is not initialized. C) The program compiles but has a runtime error because i does not have an initial value when it is used in i = i + 4; D) The program compiles and runs fine. 21) Which of the following expression results in a value 1? A) 25 % 5 B) 15 % 4 C) 37 % 6

21) D) 2 % 1

22) Which of the following assignment statements is illegal? (Choose all that apply.) A) int t = (int)false; B) float f = -34; C) short s = 10; D) int t = 4.5; E) int t = 23;

22)

23) What is the value of (double)(5/2)? A) 2.0 B) 3

C) 2.5

D) 2

E) 3.0

23)

24) -25 % 5 is ________. A) 1

C) 3

D) 4

E) 0

25) -24 % -5 is ________. A) 3 B) -3

C) 4

D) -4

E) 0

26) -24 % 5 is ________. A) -1

C) -3

D) -4

E) 0

24) B) 2

25)

26) B) -2

27) ________ is the code with natural language mixed with Java code. A) A Java statement B) A flowchart diagram C) Pseudocode D) Java program

3

27)

28) To check whether a char variable ch is an uppercase letter, you write ________. A) (ʹAʹ = ʹZʹ) C) (ch >= ʹAʹ || ch = ʹAʹ && ch = 100)    System.out.println(ʺtoo hotʺ); else if (temperature