You are on page 1of 13

1. The following code will allow the program to obtain a name from the keyboard String name = Console.

readLine("Enter name); [a] true [b] false

2. The method length( ) will return an integer which represents the length of a string value. [a] true [b] false

3. The name of a variable is known as its: [a] identifier [b] constant [c] data type [d] base

. !ll variables must be declared before they can be used. [a] true [b] false

". !ll strings end with a null #ero inside memory. [a] true [b] false

$. %ariable names may begin with a number. [a] true [b] false

&. The 'onsole commands re(uire that )ree#y*+, be imported.

[a] true [b] false

-. ,n .ava/ "02 1 [a] 2 [b] 2.5 [c] 3 [d] none of the above

2. ,n .ava/ the 3 refers to [a] percentages [b] modulus operator [c] division [d] data storage

14. The method toLowerCase( ) changes all lowercase letters to uppercase and all uppercase letters to lowercase. [a] true [b] false

11. %ariables that describe the data stored at that particular memory location are called [a] identifiers [b] constant variables [c] floating point variables [d] mnemonic variables

12. !rray inde5ing always starts with the number

[a] 4 [b] 1 [c] 2 [d] /0

13. The following statement is valid double price = 7, !".#$; [a] true [b] false

1 . ,n .ava/ 123" 1 [a] 1 [b] 2 [c] 3 [d] 4

1". The method inde%&'(",") will allow you to search for the location of a comma. [a] true [b] false

1$. 6athematicians and computers interpret the e(ual sign 718 in the same way. [a] true [b] false

1&. ! character variable may contain up to seven letters. [a] true [b] false

1-. 9hen a data type must contain decimal numbers/ assign the type [a] int [b] char [c] double [d] long int

12. %ariables that are declared/ but not initiali#ed/ contain [a] blank spaces [b] eros [c] :garbage: values [d] nothing ! they are e"pty

24. ! variable is given a value through [a] os"osis [b] as assignment statement [c] the i"port state"ents [d] the public class declarations

#hat is the si e of a double variable in $ava% a. b. c. d. 2 bytes 4 bytes - bytes &t depends on the co"piler setting

e. &t depends on the operating syste" #hat is displayed by 2.


System.out.println("1" + new Integer(2) + 3);

a.

'he state"ent has a synta( error and )on*t co"pile

b. c. d.

+ 15 123

3.

e. ,lass,ast-(ception #hich of the follo)ing best describes the set of all pairs of values for boolean variables a and b. such that
(!a && b) !(a !! b)

evaluates to true% a. b. c. d. e. -"pty set /nly one pair0 a


true" b #alse

Two pairs in which a == true ')o pairs in )hich a !


b

1ll four possible co"binations of values

#hen you try to co"pile $y%lass. the 5ava co"piler gives an error "essage 4.
2134

$y%lass is not abstra&t and does not o'erride abstra&t met(od )some met(od* in +a'a.util.%omparator

#hich of the follo)ing is )some met(od* in the error "essage% a. b. c. d.


e,uals(my%lass) &ompare-o(my%lass) &ompare(my%lass" my%lass) &ompare-o(+a'a.lang..b+e&t)

e. compare(java.lang.Object, java.lang.Object) ,onsider the follo)ing classes0 5.


publi& &lass /ear2001 2 publi& String toString() 2 return "2001"; 3 3 publi& &lass -est2001 e4tends /ear2001 2

publi& 'oid print() 2 )missing statement* 3

#hich of the follo)ing could replace )missing statement* so that -est2001 )ould co"pile )ith no errors and
-est2001 test test.print(); new -est2001();

)ould display 2001% &. System.out.println(new /ear2001()); &&. System.out.println(new -est2001()); &&&. System.out.println(t(is); a. b. c. d. e. & only && only & and && && and &&& ,/ ,,/ and ,,,

#hat is the value of a516 after the follo)ing code is e(ecuted%


int56 a 20" 2" 7" 1" 33; #or (int i 0; i ) a.lengt(; i++) a5i6 a5(a5i6 + 3) 8 a.lengt(6;

a. b. c. d.

0 1 2 3

e. 4 ,onsider the "ethod


publi& String mystery(String s) 2 String s1 s.substring(0"1); String s2 s.substring(1" s.lengt(() 9 1); String s3 s.substring(s.lengt(() 9 1); i# (s.lengt(() ) 3)

return s3 + s2 + s1; else 3 return s1 + mystery(s2) + s3;

#hat is the output of


System.out.println(mystery(":;<I=;>"));

a. b. c. d. e. ,onsider the follo)ing code seg"ent0 :.


2134

6-7&8-9 ;<%,=<> 9-8&7-6 9-7&8-6 67-&-89

<ist list new <in?ed<ist(); list.add("5"); list.add("@"); System.out.println(list);

list.add("6");

<istIterator it list.listIterator(); w(ile(it.(asAe4t() 2 i# ("5".e,uals(it.ne4t()) !! "6".e,uals(it.ne4t())) it.remo'e(); else it.add("B"); 3 System.out.println(list);

'he first output line is


55" @" 66

#hat is the second output line% a. b. c. d. e.


[A] 5@" C6 5C" @6 %lass%ase;4&eption AoSu&(;lement;4&eption

;.

#hich of the follo)ing is not a "ethod of +a'a.util.@rray<ist% a. b. c. d. e.


add(.b+e&t 4); remo'e(.b+e&t 4); insert(int i, Object x); &ontains(.b+e&t 4); set(int i" .b+e&t 4);

?uestions 14@11 refer to


publi& inter#a&e Inter#a&e@ 2 'oid met(od@(); 3 publi& inter#a&e Inter#a&eC e4tends Inter#a&e@ 2 'oid met(odC(); 3 publi& &lass %lass@ implements Inter#a&e@ 2 publi& 'oid met(od@() 23 publi& 'oid met(odC() 23 3 publi& &lass %lassC e4tends %lass@ implements Inter#a&eC 2 publi& %lassC() 23 ... )met(ods not s(own* 3

10.

#hat is the "ini"u" nu"ber of "ethods that "ust be defined in &lassC for it to co"pile )ith no errors% a. b. c. d. e. <o particular "ethods are re=uired
met(od@ met(odC met(od@ met(od@

and met(odC . met(odC. and toString

11.

#hich of the follo)ing state"ents causes a synta( error% a. b.


Inter#a&e@ ob+ Inter#a&eC ob+ new %lass@(); new %lass@();

c. d.

Inter#a&e@ ob+ Inter#a&eC ob+

new %lassC(); new %lassC();

e. %lass@ ob+ new %lassC(); ?uestions 12@13 refer to the following method rotate that takes a two@dimensional array a and retu
publi& int5656 rotate(int5656a) 2 int rows )e4pression 1*; int &ols )e4pression 2*; int5656 b )e4pression 3*; #or (int r 0; r ) rows; r++) #or (int & 0; & ) &ols; &++) b5r65&6 )e4pression 7*; return b; 3

>or e(a"ple. if a holds


1 2 3 7 1 D b 3 D 2 1 1 7 rotate(a)

)ill hold

12. #hich of the follo)ing should replace )e4pression 1*. )e4pression 2*. and )e4pression 3*%
2134

?e(pression 1@ a. b. c. d. e.
a.&ols a.&ols a.&ols()

?e(pression 2@
a.rows a.rows a.rows() a.lengt( a.lengt(

?e(pression 3@
new int(rows" &ols) new int5656(rows" &ols) new int(rows" &ols) new int5rows65&ols6 new int5656(rows" &ols)

a506.lengt( a506.lengt(

13. #hich of the follo)ing should replace )statement 7*%


2134

a.

a5&65r6

b. c. d.

a5&65rows 9 1 9 r6 a5&ols 9 1 9 &65r6 a5&ols 9 1 9 &65rows 9 1 9 r6

e. a5rows 9 1 9 r65&ols 9 1 9 &6 #hat is the value of n after the follo)ing code is e(ecuted% 14.
int n 2001; #or (int i 0; i ) 10; i++) n (n + 3) E 2;

a. b. c. d.

0 1 2 3

e. +5 #hat is the output of the follo)ing code seg"ent% 15.


<ist &ities new @rray<ist(); &ities.add("@tlanta"); &ities.add("Coston"); #or (int i 1; i ) &ities.siFe(); i++) &ities.add(i" "+"); System.out.println(&ities);

a. b. c. d. e. 1+.

5@tlanta" Coston6 5@tlanta" +" Coston6 5@tlanta" Coston" +6 5@tlanta" +" Coston" +6

<o output because the progra" goes into an infinite loop

#hich of the follo)ing state"ents is true% a. b. c. 1 static variable cannot be initiali ed in a constructor 1 static variable "ust be declared final 1n instance variable can*t be declared final

d. e.
2134

1 static "ethod can*t access an instance variable /nly a static "ethod can access a static variable

a and b are arrays of integers and each of the" has n ele"ents. a is sorted in ascending order and b is sort 1A. co"parisons in an opti"al algorith" that deter"ines )hether there e(ists i. such that a5i6 b5i6%

a. b. c. d.

O2log n4 O2 2log n42 4 O2n4 O2n log n4

e. O2n24 #hat is the output of the follo)ing code% 1:.


2134 String

?ey ""; $ap map new -ree$ap(); #or (int ? 0; ? ) 3; ?++) 2 ?ey + ?; String 'alue "@"; map.put(?ey" 'alue); 'alue + "C"; map.putG?ey" 'alue); 3 System.out.println(map.siFe());

a. b. c. d.

1 2 3 4

e. + ,onsider the follo)ing "ethod0 1;.


2134 pri'ate

-reeAode mysteryHro&ess(-reeAode root) null))

i# (root null !! (root.get<e#t() null && root.get>ig(t() return null; else 2 root.set<e#t(mysteryHro&ess(root.get<e#t())); root.set>ig(t(mysteryHro&ess(root.get>ig(t())); return root; 3

&f root refers to the root of the tree


1 E I E 7 2 1 3 E I D

)hich of the follo)ing trees is returned by mysteryHro&ess(root)% a.


1

b.

1 I

c.
3 2

1 E I

#hat is the output of the follo)ing code% 20.


2134

Sta&? st? new @rraySta&?(); st?.pus(("@"); st?.pus(("C"); st?.pus((st?); w(ile(!st?.is;mpty()) 2 .b+e&t ob+ st?.pop(); i# (ob+ instan&e.# Sta&?) 2 w(ile(!((Sta&?)ob+).is;mpty()) 2 System.out.print(((Sta&?)ob+).pop()); 3 else System.out.print(ob+); 3

a. b. c. d. e.

C@ @CC@ C@@C C@C@

,lass,ast-(ception

1 priority =ueue is represented as a "ini"u" heap. stored in an array. #hen a node 21. is added to the heap. it is first added at the left"ost vacant spot in the current level 2134 2or. if the current level is full. at the left"ost spot in the ne(t level4. and then the reheap!up procedure is applied. #hat is the order of the values in the array after B$B.

B@B. BAB. BJB. B.B. B;B. BSB are added to the =ueue% a. b. c. d. e.
@;J$A.S @J;$.AS @;J$A.S @;JS.$A @J;SA.$

Cuppose an array of n ele"ents is stored in ascending order. 'hen 5 ele"ents are 22. picked rando"ly and assigned rando" values. #hich of the follo)ing sorting 2134 algorith"s guarantees to restore the ascending order in than array using no "ore than O2n4 co"parisons% &. Celection Cort a. b. c. d. e. &&. &nsertion Cort & only && only & and && && and &&& &. &&. and &&& &&&. Dergesort

You might also like