You are on page 1of 11

MULTIPLE CHOICE 1. To compile a program named First, use the following command a. java First.java b. javac First c.

javac First.java d. compile First.javac

2. A Java program must have at least one of these: a. Class definition b. Variable c. Comment d. System.out.println(); statement

. The !!!!!!!!!!! is normall" considered the standard output and standard input devices, and usuall" refer to the monitor and #e"board. a. C$T b. C%& c. secondar" storage devices d. console

'. (f the following Java statements are e)ecuted, what will be displa"ed* System.out.println("The top three winners are\n"); System.out.print("Jody, the iant\n"); System.out.print("!u""y, the !ar#arian"); System.out.println("$delle, the $lli%ator"); a. The top three winners are Jod", the +iant ,uff", the ,arbarian Adelle, the Alligator b. The top three winners are Jod", the +iant-n,uff", the ,arbarianAdelle, the Alligator c. The top three winners are Jod", the +iant-n,uff", the ,arbarianAdelle, and the Albino d. The top three winners are Jod", the +iant ,uff", the ,arbarianAdelle, the Alligator

.. This is a value that is written into the code of a program. a. literal b. assignment statement c. variable d. operator

/. 0hat would be printed out as a result of the following code* System.out.println("The &uic' #rown "o(" ) "jumped over the \n" "slow movin% hen."); a. The 1uic# brown fo) 2umped over the -nslow moving hen. b. The 1uic# brown fo) 2umped over the slow moving hen. c. The 1uic# brown fo) 2umped over the slow moving hen. d. 3othing. This is an error.

4. 0hich of the following is not a rule that must be followed when naming identifiers* a. b. c. d. The first character must be one of the letters a56, A57, and underscore or a dollar sign. (dentifiers can contain spaces. &ppercase and lowercase characters are distinct. After the first character, "ou ma" use the letters a56, A57, the underscore, a dollar sign, or digits 85 9.

:. 0hich of the following is not a primitive data t"pe* a. short b. lon% c. "loat d. Strin%

9. 0hich of the following is valid* a. "loat y; y * +,.-; b. "loat y; dou#le .; . * -/,.01; y * .; "loat w; w * 1.2"; "loat v; v * 1.2;

c. d.

18. The #oolean data t"pe ma" contain values in the following range of values a. true or "alse b. 512: to ; 124

c. d.

5 2,1'4,': ,/': to ;2,1'4,': ,/'4 5 2,4/: to ; 2,4/4

11. Character literals are enclosed in !!!!!< string literals are enclosed in !!!!!. a. single 1uotes< single 1uotes b. double 1uotes< double 1uotes c. single 1uotes< double 1uotes d. double 1uotes< single 1uotes

12. 0hat is the result of the following e)pression* 12 ) + 3 / 4 02 a. b. c. d. 5. . 2. 5.8

1 . 0hat is the result of the following e)pression* 0+ 5 , ) , 3 12 6 / a. b. c. d. 19 ..2. 4

1'. 0hat will be displa"ed as a result of e)ecuting the following code* int ( * +, y * 02; ( )* /0; y 5* ,; System.out.println("( * " ) ( ) ", y * " ) y); a. ( = 2, y = '

b. c. d.

( = 9, y = .2 ( = 4, y = . ( = 1/8, y = :8

1.. 0hat will be the value of . as a result of e)ecuting the following code* int ( * +, y * 07; "loat .; . * ("loat) (y 5 (); a. b. c. d. ../8 ../ .8 ..8

1/. 0hat will be the displa"ed when the following code is e)ecuted* "inal int ( * 00, y * ,; y )* (; System.out.println("( * " ) ( ) ", y * " ) y); a. b. c. d. ) = 22, " = ' ) = 22, " = 2/ ) = 22, " = :: 3othing, this is an error

14. (n the following Java statement what value is stored in the variable name* Strin% name * "John 8oe"; a. b. c. d. John >oe The memor" address where ?John >oe? is located name The memor" address where name is located

1:. 0hat will be displa"ed as a result of e)ecuting the following code* int ( * 9; Strin% ms% * ": am enjoyin% this class."; Strin% ms%1 * ms%.to;pper<ase(); Strin% ms%0 * ms%.to=ower<ase(); char ltr * ms%.char$t((); int strSi.e * ms%.len%th(); System.out.println(ms%); System.out.println(ms%1); System.out.println(ms%0); System.out.println("<haracter at inde( ( * " ) ltr); System.out.println("ms% has " ) strSi.e ) "characters."); a. ( am en2o"ing this class. ( A@ A3JBC(3+ TD(E CFAEE. i am en2o"ing this class. Character at inde) ) = e msg has 2' characters. ( am en2o"ing this class. ( A@ A3JBC(3+ TD(E CFAEE. i am en2o"ing this class. Character at inde) ) = e msg has 2. characters. ( am en2o"ing this class. ( A@ A3JBC(3+ TD(E CFAEE. i am en2o"ing this class. Character at inde) ) = n msg has 2' characters. ( am en2o"ing this class. ( A@ A3JBC(3+ TD(E CFAEE. i am en2o"ing this class. Character at inde) ) = n msg has 2.characters.

b.

c.

d.

19. 0hat will be displa"ed as a result of e)ecuting the following code* pu#lic class test > pu#lic static void main(Strin%?@ ar%s) > int value1 * -; System.out.println(value1); int value0 * ,+; System.out.println(value0); System.out.println(value/); value * 19; A A a. b. c. d. 9 '. 1/ 9'.1/ 9 '. 1/ 3othing, this is an error

28. 0hich of the following is not a valid comment statement* a. 55 comment 1 b. 53 comment 0 35 c. 35 comment / 53 d. 533 comment , 35

21. 0hen saving a Java source file, save it with an e)tension of a. .javac b. .class c. .src d. .java

22. Aver" Java application program must have a. a class named B$:C b. a method named main c. comments d. integer variables

2 . To print ?Dello, world? on the monitor, use the following Java statement a. SystemDutErintln("Fello, world"); b. System.out.println>"Fello, world"A c. System.out.println("Fello, world"); d. Erint "Fello, world";

2'. To displa" the output on the ne)t line, "ou can use the println method or use this escape se1uence in the print method. a. b. c. d. \n \r \t \#

2.. This is a named storage location in the computerGs memor". a. Fiteral b. Constant c. Variable d. Bperator

2/. 0hat would be displa"ed as a result of the following code* int ( * +G7; System.out.print("There are " ) ( ) + ) "\n" ) "hens in the hen house."); a. b. c. d. There are .: hens in the hen house. There are .4:. hens in the hen house. There are ).-nhens in the hen house. There are .4:. hens in the hen house.

24. Variables are classified according to their a. value

b. c. d.

data t"pe names location in the program

2:. The primitive data t"pes onl" allow aHnI !!!!! to hold a single value. a. variable b. ob2ect c. class d. literal

29. (f ( has been declared an int, which of the following statements is invalid* a. ( * 2; b. ( * 4+7-/0; c. ( * 1,222; d. ( * +-0;

8. +iven the declaration dou#le r;, which of the following statements is invalid* a. r * /09.G+; b. r * -.,9/0e1+; c. r * -.,9/0H1+; d. r * 0.-I129;

1. Variables of the #oolean data t"pe are useful for a. wor#ing with small integers b. evaluating trueJfalse conditions c. wor#ing with ver" large integers d. evaluating scientific notation

2. 0hat is the result of the following e)pression* 0+ 4 G 3 / ) 10 5 / a. b. c. d. / : 18 12

. 0hat is the result of the following e)pression* 1G 6 / 3 0 4 10 ) 1+ a. b. c. d. 4 : 12 18.

'. 0hat will be displa"ed after the following statements have been e)ecuted* int ( * 1+, y * 02, . ( )* 10; y 5* 9; . 4* 1,; System.out.println("( ", ", a. b. c. d. ) = 24, " = . , 6 = 1: ) = 24, " = 2, 6 = 1: ) = 24, " = , 6 = 1: ) = 4, " = 1', 6 = ' * /0;

* " ) ( ) y * " ) y ) . * " ).);

.. 0hat will be the value of . after the following statements have been e)ecuted* int ( * ,, y * //; dou#le .; . * (dou#le) (y 5 (); a. b. c. d. :.2. ' : :.8

/. This is a variable whose content is read onl" and cannot be changed during the programGs e)ecution. a. b. c. d. operator literal named constant reserved word

4. 0hat will be displa"ed after the following statements have been e)ecuted* "inal dou#le (; ( * +,./; System.out.println("( * " ) ( );

a. b. c. d.

) = .'. ) ) = 18:./ 3othing, this is an error.

:. 0hich of the following is a valid Java statement* a. Strin% str * JJohn 8oeJ; b. strin% str * "John 8oe"; c. strin% str * JJohn 8oeJ; d. Strin% str * "John 8oe";

9. 0hat will be displa"ed as a result of e)ecuting the following code* int ( * 7; Strin% ms% * ": am enjoyin% java."; Strin% ms%1 * ms%.to;pper<ase(); Strin% ms%0 * ms%.to=ower<ase(); char ltr * ms%.char$t((); int strSi.e * ms%.len%th(); System.out.println(ms%); System.out.println(ms%1); System.out.println(ms%0); System.out.println("<haracter at inde( ( * " ) ltr); System.out.println("ms% has " ) strSi.e ) " characters."); a. ( am en2o"ing 2ava. ( A@ A3JBC(3+ JAVA. i am en2o"ing 2ava. Character at inde) ) = 2 msg has 28 characters. ( am en2o"ing 2ava. ( A@ A3JBC(3+ JAVA. i am en2o"ing 2ava. Character at inde) ) = o msg has 28 characters. ( am en2o"ing 2ava. ( A@ A3JBC(3+ JAVA. i am en2o"ing 2ava. Character at inde) ) = o msg has 19 characters. ( am en2o"ing 2ava. ( A@ A3JBC(3+ JAVA. i am en2o"ing 2ava. Character at inde) ) = " msg has 19 characters.

b.

c.

d.

'8. 0hich of the following does not describe a valid comment in Java* a. Eingle line comments, two forward slashes 5 55 b. @ulti5line comments, start with 53 and end with 35 c. @ulti5line comments, start with 35 and end with 53 d. >ocumentation comments, an" comments starting with 533 and ending with 35

'1. 0hich of the following statements correctl" creates a Scanner ob2ect for #e"board input* a. b. c. d. Scanner '#d * new Scanner(System.'ey#oard); Scanner 'ey#oard(System.in); Scanner 'ey#oard * new Scanner(System.in); Key#oard scanner * new Key#oard(System.in);

'2. 0hich Scanner class method reads an int* a. b. read:nt() ne(t:nt() c. d. %et:nt() readLint()

' . 0hich Scanner class method reads a Strin%* a. b. readStrin%() ne(tStrin%() c. d. %etStrin%() ne(t=ine()

You might also like