You are on page 1of 31

OOPs

Q: 01 Click the Task button.

Solution: Alpha.foo Beta.ba Beta.foo Beta.bar Q: 02 Given: public class Plant private Strin! na"e# public Plant$Strin! na"e% this.na"e & na"e# ' public Strin! !et(a"e$% return na"e# ' ' 1. public class Tree e)ten*s Plant 2. public voi* !ro+,ruit$% ' -. public voi* *rop.eaves$% ' /. ' 0hich state"ent is true1 A. The code will compile without changes. B. The code will compile if public Tree() { Plant(); } is added to the Tree class. C. The code will compile if public Plant() { Tree(); } is added to the Plant class. . The code will compile if public Plant() { this(!fern!); } is added to the Plant class. ". The code will compile if public Plant() { Plant(!fern!); } is added to the Plant class. Ans+er: 2 Q: 0- Click the 3)hibit button. 0hich state"ent is true about the classes an* interfaces in the e)hibit1

A. Compilation will succeed for all classes and interfaces. B. Compilation of class C will fail because of an error in line #. C. Compilation of class C will fail because of an error in line $. . Compilation of class A%mpl will fail because of an error in line #. Ans+er: C Q: 0/ Given: 11. public class 4ikes 12. 1-. public static voi* !o$.on! n% S5ste".out.println$6.on! 6%#' 1/. public static voi* !o$Short n% S5ste".out.println$6Short 6%#' 17. public static voi* !o$int n% S5ste".out.println$6int 6%#' 18. public static voi* "ain$Strin! 9: ar!s% 1;. short 5 & 8# 1<. lon! = & ;# 1>. !o$5%# 20. !o$=%# 21. ' 22. ' 0hat is the result1 A. int &ong B. 'hort &ong C. Compilation fails. . An e(ception is thrown at runtime. Ans+er: A Q: 07 Click the Task button.

Solution: class
class

A has na"e
B hasna"eA

Q: 08 0hich t+o state"ents are true about has?a an* is?a relationships1 $Choose t+o.% A. %nheritance represents an is)a relationship. B. %nheritance represents a has)a relationship. C. %nterfaces must be used when creating a has)a relationship. . %nstance *ariables can be used when creating a has)a relationship. Ans+er: A@ 2 Q: 0; Given: 10: public class Aello 11: Strin! title# 12: int value# 1-: public Aello$% 1/: title B& 6 0orl*6# 17: ' 18: public Aello$int value% 1;: this.value & value# 1<: title & 6Aello6# 1>: Aello$%# 20: ' 21: ' an*: -0: Aello c & ne+ Aello$7%# -1: S5ste".out.println$c.title%# 0hat is the result1 A. +ello B. +ello ,orld C. Compilation fails.

. +ello ,orld ". The code runs with no output. .. An e(ception is thrown at runtime. Ans+er: C Q: 0< Given: 1. class Super 2. private int a# -. protecte* Super$int a% this.a & a# ' /. ' ... 11. class Sub e)ten*s Super 12. public Sub$int a% super$a%# ' 1-. public Sub$% this.a & 7# ' 1/. ' 0hich t+o@ in*epen*entl5@ +ill allo+ Sub to co"pile1 $Choose t+o.% A. Change line # to/ public int a; B. Change line # to /protected int a;
C. Change line 01 to /public 'ub() { this(-); } . Change line 01 to /public 'ub() { super(-); } ". Change line 01 to /public 'ub() { super(a); }

Ans+er: C@ 2 Q: 0> Click the Task button.

Solution: Car is a Cehicle an* car is a Collectable Car has a Steerin! 0heel car has 0heels

class A D &&&&&&&&&&&&&&&&&&E ' D &&&&&&&&&&&&&&&&&&E class A B b# ' class A .ist DBE b# ' class A e)ten*s B ' i"ple"ents B @ C

D &&&&&&&&&&&&&&&&&&E D &&&&&&&&&&&&&&&&&&E

Fini is a Car

Car is an GbHect

D &&&&&&&&&&&&&&&&&&E

class A '

Q: 10 Given: 1. class ClassA 2. public int nu"berGfInstances# -. protecte* ClassA$int nu"berGfInstances% /. this.nu"berGfInstances & nu"berGfInstances# 7. ' 8. ' ;. public class 3)ten*e*A e)ten*s ClassA <. private 3)ten*e*A$int nu"berGfInstances% >. super$nu"berGfInstances%# 10. ' 11. public static voi* "ain$Strin!9: ar!s% 12. 3)ten*e*A e)t & ne+ 3)ten*e*A$/20%# 1-. S5ste".out.print$e)t.nu"berGfInstances%# 1/. ' 17. ' 0hich state"ent is true1 A. 2#3 is the output. B. An e(ception is thrown at runtime. C. All constructors must be declared public. . Constructors CA445T use the pri*ate modifier. ". Constructors CA445T use the protected modifier. Ans+er: A Q: 11 Given: 1. interface A public voi* aFetho*$%# ' 2. interface B public voi* bFetho*$%# ' -. interface C e)ten*s A@B public voi* cFetho*$%# ' /. class 2 i"ple"ents B 7. public voi* bFetho*$% ' 8. ' ;. class 3 e)ten*s 2 i"ple"ents C <. public voi* aFetho*$% ' >. public voi* bFetho*$% ' 10. public voi* cFetho*$% ' 11. ' 0hat is the result1 A. Compilation fails because of an error in line 1. B. Compilation fails because of an error in line 6. C. Compilation fails because of an error in line 7. . %f 8ou define e 9 new "(): then e.b;ethod() in*o<es the *ersion of b;ethod() defined in &ine -. ". %f 8ou define e 9 ( )(new "()): then e.b;ethod() in*o<es the *ersion of b;ethod() defined in &ine -. .. %f 8ou define e 9 ( )(new "()): then e.b;ethod() in*o<es the *ersion of b;ethod() defined in &ine 7. Ans+er: , Q: 12 Given: 1. public class Base 2. public static final Strin! ,GG & 6foo6# -. public static voi* "ain$Strin!9: ar!s% /. Base b & ne+ Base$%# 7. Sub s & ne+ Sub$%# 8. S5ste".out.print$Base.,GG%# ;. S5ste".out.print$Sub.,GG%#

<. S5ste".out.print$b.,GG%# >. S5ste".out.print$s.,GG%# 10. S5ste".out.print$$$Base%s%.,GG%# 11. ' ' 12. class Sub e)ten*s Base public static final Strin! ,GG&6bar6#' 0hat is the result1
A. foofoofoofoofoo

B. foobarfoobarbar
C. foobarfoofoofoo

. foobarfoobarfoo ". barbarbarbarbar .. foofoofoobarbar


=. foofoofoobarfoo

Ans+er: 2 Q: 1- 0hich t+o state"ents are true1 $Choose t+o.% A. An encapsulated: public class promotes re)use. B. Classes that share the same interface are alwa8s tightl8 encapsulated. C. An encapsulated class allows subclasses to o*erload methods: but does 45T allow o*erriding methods. . An encapsulated class allows a programmer to change an implementation without affecting outside code. Ans+er: A@ 2 Q: 1/ Given: 11. public static voi* test$Strin! str% 12. if $str && null J str.len!th$% && 0% 1-. S5ste".out.println$6Strin! is e"pt56%# 1/. ' else 17. S5ste".out.println$6Strin! is not e"pt56%# 18. ' 1;. ' An* the invocation: -1. test$null%# 0hat is the result1 A. An e(ception is thrown at runtime. B. !'tring is empt8! is printed to output. C. Compilation fails because of an error in line 0#. . !'tring is not empt8! is printed to output. Ans+er: A Q: 17 Given: 12. public class 0o+ 1-. public static voi* !o$short n% S5ste".out.println$6short6%#' 1/. public static voi* !o$Short n% S5ste".out.println$6SAGKT6%#' 17. public static voi* !o$.on! n% S5ste".out.println$6 .G(G6%#' 18. public static voi* "ain$Strin! 9: ar!s% 1;. Short 5 & 8# 1<. int = & ;# 1>. !o$5%# 20. !o$=%# 21. ' 22. ' 0hat is the result1 A. short &54= B. '+5>T &54= C. Compilation fails. . An e(ception is thrown at runtime.

Ans+er: C Q: 18 Click the 3)hibit button. 0hich three co*e fra!"ents@ a**e* in*ivi*uall5 at line 2>@ pro*uce the output 1001 $Choose three.%

A. n 9 033; B. i.set?( 033 ); C. o.get@().set?( 033 ); . i 9 new %nner(); i.set?( 033 ); ". o.set@( i ); i 9 new %nner(); i.set?( 033 ); .. i 9 new %nner(); i.set?( 033 ); o.set@( i ); Ans+er: B@ C@ , Q: 1; Given: 10. class Gne 11. public Gne$% S5ste".out.print$1%# ' 12. ' 1-. class T+o e)ten*s Gne 1/. public T+o$% S5ste".out.print$2%# ' 17. ' 18. class Three e)ten*s T+o 1;. public Three$% S5ste".out.print$-%# ' 1<. ' 1>. public class (u"bers 20. public static voi* "ain$ Strin!9: ar!v % ne+ Three$%# ' 21. ' 0hat is the result +hen this co*e is e)ecute*1 A. 0 B. 1 C. 0#1 . 1#0 ". The code runs with no output. Ans+er: C Q: 1< Click the 3)hibit button. 0hat is the outco"e of the co*e1

A. Compilation fails. B. =obstopper .iAA8lifting C. =obstopper 'crumdiddl8umptious . 'crumdiddl8umptious .iAA8lifting ". 'crumdiddl8umptious Ans+er: B Q: 1> Given: 10. class Gne 11. public Gne foo$% return this# ' 12. ' 1-. class T+o e)ten*s Gne
1/. public Gne foo$% return this# '

17. ' 18. class Three e)ten*s T+o 1;. LL insert "etho* here 1<. ' 0hich t+o "etho*s@ inserte* in*ivi*uall5@ correctl5 co"plete the Three class1 $Choose t+o.%
A. public *oid foo() {} B. public int foo() { return 1; } C. public Two foo() { return this; } . public 5ne foo() { return this; } ". public 5bBect foo() { return this; }

Ans+er: C@ 2 Q: 20 Click the 3)hibit button. 0hat is the output of the pro!ra" sho+n in the e)hibit1

A. 133)033)033)033)033
B. 133)133)033)033)033 C. 133)133)133)033)033

. 133)133)133)133)033

Ans+er: B Q: 21 Click the Task button.

Solution: public voi* bar$int )% ' public int bar$Strin! )% return 1# ' public voi* bar$int )@int 5% ' Q: 22 Given: 10. interface A public int !etCalue$%# ' 11. class B i"ple"ents A 12. public int !etCalue$% return 1# ' 1-. '

1/. class C e)ten*s B


17. LL insert co*e here

18. ' 0hich three co*e fra!"ents@ inserte* in*ivi*uall5 at line 17@ "ake use of pol5"orphis"1 $Choose three.%
A. public *oid add(C c) { c.getCalue(); } B. public *oid add(B b) { b.getCalue(); } C. public *oid add(A a) { a.getCalue(); } . public *oid add(A a: B b) { a.getCalue(); } ". public *oid add(C c0: C c#) { c0.getCalue(); }

Ans+er: B@ C@ 2 Q: 2- Click the 3)hibit button. 0hat is the result1

A. snootch8 2#3 third second first B. snootch8 2#3 first second third C. first second third snootch8 2#3 . third second first snootch8 2#3 ". third first second snootch8 2#3 .. first second first third snootch8 2#3 Ans+er: 2 Q: 2/ Given: 10. abstract class A 11. abstract voi* a1$%# 12. voi* a2$% ' 1-. ' 1/. class B e)ten*s A 17. voi* a1$% ' 18. voi* a2$% '

1;. ' 1<. class C e)ten*s B voi* c1$% ' ' an*: A ) & ne+ B$%# C 5 & ne+ C$%# A = & ne+ C$%# 0hat are four vali* e)a"ples of pol5"orphic "etho* calls1 $Choose four.% A. (.a#(); B. A.a#(); C. A.c0(); . A.a0(); ". 8.c0(); .. (.a0(); Ans+er: A@ B@ 2@ , Q: 27 Click the 3)hibit button. 0hat is the result1

A. Calue is/ D B. Compilation fails. C. Calue is/ 0# . Calue is/ )0# ". The code runs with no output. .. An e(ception is thrown at runtime. Ans+er: A Q: 28 Given: 20. public class Cre*itCar* 21. 22. private Strin! car*I2# 2-. private Inte!er li"it# 2/. public Strin! o+ner(a"e# 27. 28. public voi* setCar*Infor"ation$Strin! car*I2@ 2;. Strin! o+ner(a"e@ 2<. Inte!er li"it% 2>. this.car*I2 & car*I2# -0. this.o+ner(a"e & o+ner(a"e# -1. this.li"it & li"it# -2. '

--. ' 0hich state"ent is true1 A. The class is full8 encapsulated. B. The code demonstrates pol8morphism. C. The owner4ame *ariable brea<s encapsulation. . The card% and limit *ariables brea< pol8morphism. ". The setCard%nformation method brea<s encapsulation. Ans+er: C Q: 2;Given: 11. class Ani"al public Strin! noise$% return 6peep6# ' ' 12. class 2o! e)ten*s Ani"al 1-. public Strin! noise$% return 6bark6# ' 1/. ' 17. class Cat e)ten*s Ani"al 18. public Strin! noise$% return 6"eo+6# ' 1;. ' ... -0. Ani"al ani"al & ne+ 2o!$%# -1. Cat cat & $Cat%ani"al# -2. S5ste".out.println$cat.noise$%%# 0hat is the result1 A. peep B. bar< C. meow . Compilation fails. ". An e(ception is thrown at runtime. Ans+er: 3 Q: 2< Click the Task button.

Solution: 2o! ,orest Kectan!le MavaBook

is?a has?a has?a is?a

Ani"al Tree Si*e Pro!ra""in!Book

Q: 2> 0hich three state"ents are true1 $Choose three.% A. A final method in class ? can be abstract if and onl8 if ? is abstract. B. A protected method in class ? can be o*erridden b8 an8 subclass of ?. C. A pri*ate static method can be called onl8 within other static methods in class ?. . A non)static public final method in class ? can be o*erridden in an8 subclass of ?. ". A public static method in class ? can be called b8 a subclass of ? without e(plicitl8 referencing the class ?. .. A method with the same signature as a pri*ate final method in class ? can be implemented in a subclass of ?. =. A protected method in class ? can be o*erridden b8 a subclass of A onl8 if the subclass is in the same pac<age as ?. Ans+er: B@ 3@ , Q: -0 0hich four state"ents are true1 $Choose four.% A. +as)a relationships should ne*er be encapsulated. B. +as)a relationships should be implemented using inheritance. C. +as)a relationships can be implemented using instance *ariables. . %s)a relationships can be implemented using the e(tends <e8word. ". %s)a relationships can be implemented using the implements <e8word. .. The relationship between ;o*ie and Actress is an e(ample of an is)a relationship. =. An arra8 or a collection can be used to implement a one)to)man8 has)a relationship. Ans+er: C@ 2@ 3@ G Q: -1Given: 10. interface Mu"per public voi* Hu"p$%# ' ... 20. class Ani"al ' ... -0. class 2o! e)ten*s Ani"al -1. Tail tail# -2. ' ... /0. class Bea!le e)ten*s 2o! i"ple"ents Mu"per /1. public voi* Hu"p$% ' /2. ' ... 70. class Cat i"ple"ents Mu"per 71. public voi* Hu"p$% ' 72. ' 0hich three are true1 $Choose three.% A. Cat is)a Animal B. Cat is)a Eumper C. og is)a Animal . og is)a Eumper ". Cat has)a Animal .. Beagle has)a Tail =. Beagle has)a Eumper Ans+er: B@ C@ , Q: -2 Click the 3)hibit button. 0hat t+o "ust the pro!ra""er *o to correct the co"pilation errors1 $Choose t+o.%

A. insert a call to this() in the Car constructor B. insert a call to this() in the ;e=o constructor C. insert a call to super() in the ;e=o constructor . insert a call to super(*in) in the ;e=o constructor ". change the wheelCount *ariable in Car to protected .. change line 1 in the ;e=o class to super.wheelCount 9 1; Ans+er: 2@ 3 Q: -- Given: 10. public class SuperCalc 11. protecte* static int "ultipl5$int a@ int b% return a N b#' 12. ' an*: 20. public class SubCalc e)ten*s SuperCalc 21. public static int "ultipl5$int a@ int b% 22. int c & super."ultipl5$a@ b%# 2-. return c# 2/. ' 27. ' an*: -0. SubCalc sc & ne+ SubCalc $%# -1. S5ste".out.println$sc."ultipl5$-@/%%# -2. S5ste".out.println$SubCalc."ultipl5$2@2%%# 0hat is the result1 A. 0# 2 B. The code runs with no output. C. An e(ception is thrown at runtime. . Compilation fails because of an error in line #0. ". Compilation fails because of an error in line ##. .. Compilation fails because of an error in line 10. Ans+er: 3

Q: -/ Given: 1.public class Blip 2. protecte* int blipvert$int )% return 0# ' -. ' /. class Cert e)ten*s Blip 7. LL insert co*e here 8. ' 0hich five "etho*s@ inserte* in*epen*entl5 at line 7@ +ill co"pile1 $Choose five.% A. public int blip*ert(int () { return 3; } B. pri*ate int blip*ert(int () { return 3; }
C. pri*ate int blip*ert(long () { return 3; } . protected long blip*ert(int () { return 3; } ". protected int blip*ert(long () { return 3; } .. protected long blip*ert(long () { return 3; } =. protected long blip*ert(int (: int 8) { return 3; }

Ans+er: A@ C@ 3@ ,@ G Q: -7 Given: 1. class Pi==a 2. Hava.util.Arra5.ist toppin!s# -. public final voi* a**Toppin!$Strin! toppin!% /. toppin!s.a**$toppin!%# 7. ' 8. ' ;. public class PepperoniPi==a e)ten*s Pi==a <. public voi* a**Toppin!$Strin! toppin!% >. S5ste".out.println$6Cannot a** Toppin!s6%# 10. ' 11. public static voi* "ain$Strin!9: ar!s% 12. Pi==a pi==a & ne+ PepperoniPi==a$%# 1-. pi==a.a**Toppin!$6Fushroo"s6%# 1/. ' 17. ' 0hat is the result1

A. Compilation fails. B. Cannot add Toppings C. The code runs with no output. . A 4ullPointer"(ception is thrown in &ine 2. Ans+er: A Q: -8 Given: 1. interface 2oStuff2 2. float !etKan!e$int lo+@ int hi!h%# ' -. /. interface 2oFore 7. float !etAv!$int a@ int b@ int c%# ' 8. ;. abstract class 2oAbstract i"ple"ents 2oStuff2@ 2oFore ' <. >. class 2oStuff i"ple"ents 2oStuff2 10. public float !etKan!e$int )@ int 5% return -.1/f# ' ' 11. 12. interface 2oAll e)ten*s 2oFore 1-. float !etAv!$int a@ int b@ int c@ int *%# ' 0hat is the result1 A. The file will compile without error. B. Compilation fails. 5nl8 line 6 contains an error. C. Compilation fails. 5nl8 line 0# contains an error. . Compilation fails. 5nl8 line 01 contains an error. ". Compilation fails. 5nl8 lines 6 and 0# contain errors. .. Compilation fails. 5nl8 lines 6 and 01 contain errors.

=. Compilation fails. &ines 6: 0#: and 01 contain errors. Ans+er: A Q: -; Click the 3)hibit button. Given: 27. A a & ne+ A$%# 28. S5ste".out.println$a.*oit$/@ 7%%# 0hat is the result1

A. &ine #$ prints !a! to '8stem.out. B. &ine #$ prints !b! to '8stem.out. C. An e(ception is thrown at line #$ at runtime. . Compilation of class A will fail due to an error in line $. Ans+er: A Q: -< Given: 1. class TestA 2. public voi* start$% S5ste".out.println$6TestA6%# ' -. ' /. public class TestB e)ten*s TestA
7. public voi* start$% S5ste".out.println$6TestB6%# '

8. public static voi* "ain$Strin!9: ar!s% ;. $$TestA%ne+ TestB$%%.start$%# <. ' >. ' 0hat is the result1 A. TestA B. TestB C. Compilation fails. . An e(ception is thrown at runtime. Ans+er: B Q: -> Given: 1. interface TestA Strin! toStrin!$%# ' 2. public class Test -. public static voi* "ain$Strin!9: ar!s% /. S5ste".out.println$ne+ TestA$% 7. public Strin! toStrin!$% return 6test6# ' 8. '%# ;. ' <. ' 0hat is the result1 A. test B. null C. An e(ception is thrown at runtime. . Compilation fails because of an error in line 0. ". Compilation fails because of an error in line 2. .. Compilation fails because of an error in line -. Ans+er: A

Q: /0 Given: 11. public class Ite"Test 12. private final int i*# 1-. public Ite"Test$int i*% this.i* & i*# ' 1/. public voi* up*ateI*$int ne+I*% i* & ne+I*# ' 17. 18. public static voi* "ain$Strin!9: ar!s% 1;. Ite"Test fa & ne+ Ite"Test$/2%# 1<. fa.up*ateI*$8>%# 1>. S5ste".out.println$fa.i*%# 20. ' 21. ' 0hat is the result1 A. Compilation fails. B. An e(ception is thrown at runtime. C. The attribute id in the %tem obBect remains unchanged. . The attribute id in the %tem obBect is modified to the new *alue. ". A new %tem obBect is created with the preferred *alue in the id attribute. Ans+er: A Q: /1 Given: 10. class Gne 11. voi* foo$% ' 12. ' 1-. class T+o e)ten*s Gne 1/. LLinsert "etho* here 17. ' 0hich three "etho*s@ inserte* in*ivi*uall5 at line 1/@ +ill correctl5 co"plete class T+o1 $Choose three.%
A. int foo() { FG more code here GF } B. *oid foo() { FG more code here GF } C. public *oid foo() { FG more code here GF } . pri*ate *oid foo() { FG more code here GF } ". protected *oid foo() { FG more code here GF }

Ans+er: B@ C@ 3 Q: /2 Given: 10. interface 2ata public voi* loa*$%# ' 11. abstract class Info public abstract voi* loa*$%# ' 0hich class correctl5 uses the 2ata interface an* Info class1 A. public class "mplo8ee e(tends %nfo implements ata {
public *oid load() { FGdo somethingGF } }

B. public class "mplo8ee implements %nfo e(tends


public *oid load() { FGdo somethingGF } }

ata { ata

C. public class "mplo8ee e(tends %nfo implements


public *oid load(){ FGdo somethingGF } public *oid %nfo.load(){ FGdo somethingGF } }

. public class "mplo8ee implements %nfo e(tends


public *oid ata.load(){ FGdo somethingGF } public *oid load(){ FGdo somethingGF } }

ata {

". public class "mplo8ee implements %nfo e(tends


public *oid load(){ FGdo somethingGF } public *oid %nfo.load(){ FGdo somethingGF } }

ata {

.. public class "mplo8ee e(tends %nfo implements


public *oid ata.load() { FGdo somethingGF } public *oid %nfo.load() { FGdo somethingGF } }

ata{

Ans+er: A Q: /- Given: 11. public abstract class Shape 12. int )# 1-. int 5# 1/. public abstract voi* *ra+$%# 17. public voi* setAnchor$int )@ int 5% 18. this.) & )# 1;. this.5 & 5# 1<. ' 1>. ' an* a class Circle that e)ten*s an* full5 i"ple"ents the Shape class. 0hich is correct1 A. 'hape s 9 new 'hape(); s.setAnchor(03:03); s.draw(); B. Circle c 9 new 'hape(); c.setAnchor(03:03); c.draw(); C. 'hape s 9 new Circle(); s.setAnchor(03:03); s.draw(); . 'hape s 9 new Circle(); s)HsetAnchor(03:03); s)Hdraw(); ". Circle c 9 new Circle(); c.'hape.setAnchor(03:03); c.'hape.draw(); Ans+er: C Q: // Click the 3)hibit button. 0hat is the result1

A. 21#0 B. 3333 C. An e(ception is thrown at runtime. . Compilation fails because of an error in line 0D. Ans+er: 2

Q: /7 Given: 10. interface ,oo ' 11. class Alpha i"ple"ents ,oo ' 12. class Beta e)ten*s Alpha ' 1-. class 2elta e)ten*s Beta 1/. public static voi* "ain$ Strin!9: ar!s % 17. Beta ) & ne+ Beta$%# 18. LL insert co*e here 1;. ' 1<. ' 0hich co*e@ inserte* at line 18@ +ill cause a Hava.lan!.ClassCast3)ception1 A. Alpha a 9 (; B. .oo f 9 ( elta)(; C. .oo f 9 (Alpha)(; . Beta b 9 (Beta)(Alpha)(; Ans+er: B Q: /8 Given: 1. class SuperClass 2. public A !etA$% -. return ne+ A$%# /. ' 7. ' 8. class SubClass e)ten*s SuperClass ;. public B !etA$% <. return ne+ B$%# >. ' 10. ' 0hich state"ent is true1 A. Compilation will succeed if A e(tends B. B. Compilation will succeed if B e(tends A. C. Compilation will alwa8s fail because of an error in line 6. . Compilation will alwa8s fail because of an error in line D. Ans+er: B Q: /; Given: 11. static class A 12. voi* process$% thro+s 3)ception thro+ ne+ 3)ception$%# ' 1-. ' 1/. static class B e)ten*s A 17. voi* process$% S5ste".out.println$6B6%# ' 18. ' 1;. public static voi* "ain$Strin!9: ar!s% 1<. ne+ B$%.process$%# 1>. ' 0hat is the result1 A. B B. The code runs with no output. C. Compilation fails because of an error in line 0#. . Compilation fails because of an error in line 0-. ". Compilation fails because of an error in line 0D. Ans+er: A Q: /< Given: 11. class ClassA ' 12. class ClassB e)ten*s ClassA ' 1-. class ClassC e)ten*s ClassA ' an*:

21. ClassA p0 & ne+ ClassA$%# 22. ClassB p1 & ne+ ClassB$%# 2-. ClassC p2 & ne+ ClassC$%#
2/. ClassA p- & ne+ ClassB$%#

27. ClassA p/ & ne+ ClassC$%# 0hich three are vali*1 $Choose three.% A. p3 9 p0; B. p0 9 p#; C. p# 9 p2; . p# 9 (ClassC)p0; ". p0 9 (ClassB)p1; .. p# 9 (ClassC)p2; Ans+er: A@ 3@ , Q: /> Given: 11. abstract class Cehicle public int spee*$% return 0# ' 12. class Car e)ten*s Cehicle public int spee*$% return 80# ' 1-. class KaceCar e)ten*s Car public int spee*$% return 170# ' ... 21. KaceCar racer & ne+ KaceCar$%# 22. Car car & ne+ KaceCar$%# 2-. Cehicle vehicle & ne+ KaceCar$%# 2/. S5ste".out.println$racer.spee*$% B 6@ 6 B car.spee*$% 27. B 6@ 6 B vehicle.spee*$%%# 0hat is the result1 A. 3: 3: 3 B. 0-3: $3: 3 C. Compilation fails. . 0-3: 0-3: 0-3 ". An e(ception is thrown at runtime. Ans+er: 2 Q: 70 Given co*e in separate source files: 10. public class ,oo 11. public int a# 12. public ,oo$% a & -# ' 1-. public voi* a**,ive$% a B& 7#' 1/. ' an*: 20. public class Bar e)ten*s ,oo 21. public int a# 22. public Bar$% a & <# ' 2-. public voi* a**,ive$% this.a B& 7# ' 2/. ' invoke* +ith: -0. ,oo foo & ne+ Bar$%# -1. foo.a**,ive$%# -2. S5ste".out.println$6Calue: 6 B foo.a%# 0hat is the result1 A. Calue/ 1 B. Calue/ D C. Calue/ 01 . Compilation fails. ". The code runs with no output. .. An e(ception is thrown at runtime. Ans+er: A Q: 71 0hich Fan class properl5 represents the relationship 6Fan has a best frien* +ho is a 2o!61
A. class ;an e(tends og { } B. class ;an implements og { }

C. class ;an { pri*ate Best.riend dog; } . class ;an { pri*ate og best.riend; } ". class ;an { pri*ate ogIbest.riendH; } .. class ;an { pri*ate Best.riendIdogH; }

Ans+er: 2 Q: 72 Given: 10. interface ,oo int bar$%# ' 11. public class Sprite 12. public int fubar$ ,oo foo % return foo.bar$%# ' 1-. public voi* test,oo$% 1/. fubar$ 17. LL insert co*e here 18. %# 1;. ' 1<. ' 0hich co*e@ inserte* at line 17@ allo+s the class Sprite to co"pile1
A. .oo { public int bar() { return 0; } B. new .oo { public int bar() { return 0; } C. new .oo() { public int bar() { return 0; } . new class .oo { public int bar() { return 0; }

Ans+er: C Q: 7- Click the Task button.

Solution: 1. int

2. h -. a"ount.

Q: 7/ Given classes *efine* in t+o *ifferent files:

1. packa!e packa!eA# 2. public class Fessa!e -. Strin! !etTe)t$% return 6te)t6# ' /. ' an*: 1. packa!e packa!eB# 2. public class OF.Fessa!e e)ten*s packa!eA.Fessa!e -. Strin! !etTe)t$% return 6D"s!Ete)tDL"s!E6#' /. public static voi* "ain$Strin!9: ar!s% 7. S5ste".out.println$ne+ OF.Fessa!e$%.!etTe)t$%%# 8. ' ;. ' 0hat is the result of e)ecutin! OF.Fessa!e."ain1 A. te(t B. An e(ception is thrown at runtime. C. Compilation fails because of an error in line # of ?;&;essage. . Compilation fails because of an error in line 1 of ?;&;essage. Ans+er: 2 Q: 77 Given: 1. public class A 2. public voi* *oit$% -. ' /. public Strin! *oit$% 7. return 6a6# 8. ' ;. public *ouble *oit$int )% <. return 1.0# >. ' 10. ' 0hat is the result1 A. An e(ception is thrown at runtime. B. Compilation fails because of an error in line 6. C. Compilation fails because of an error in line 2. . Compilation succeeds and no runtime errors with class A occur. Ans+er: C Question: 78 Click the 3)hibit button. 1. public class GoTest 2. public static voi* "ain$Strin!9: ar!s% -. Sente a & ne+ Sente$%# a.!o$%# /. Goban b & ne+ Goban$%# b.!o$%# 5. Stone c & ne+ Stone$%# c.!o$%# 6. ' 7. ' <. 9. class Sente i"ple"ents Go 10. public voi* !o$% S5ste".out.println$P!o in Sente.P%# ' 11. ' 12. 1-. class Goban e)ten*s Sente 1/. public voi* !o$% S5ste".out.println$P!o in GobanP%# ' 15. ' 18. 1;. class Stone e)ten*s Goban i"ple"ents Go ' 1<. 1>. interface Go public voi* !o$%# '

0hat is the result1 A. go in =oban go in 'ente go in 'ente B. go in 'ente go in 'ente go in =oban C. go in 'ente go in =oban go in =oban . go in =oban go in =oban go in 'ente ". Compilation fails because of an error in line 06. Ans+er: C Question: 7; Click the 3)hibit button. 1. public class 3"plo5ee 2. Strin! na"e# -. *ouble baseSalar5# /. 3"plo5ee$Strin! na"e@ *ouble baseSalar5% 7. this.na"e & na"e# 8. this.baseSalar5 & baseSalar5# ;. ' <. ' An*: 1. public class Salesperson e)ten*s 3"plo5ee 2. *ouble co""ission# -. public Salesperson$Strin! na"e@ *ouble baseSalar5@ /. *ouble co""ission% 7. LL insert co*e here 8. ' ;. ' 0hich co*e@ inserte* at line ;@ co"pletes the Salesperson constructor1 A. this.commission 9 commission; B. superb(); commission 9 commission; C. this.commission 9 commission; superb(); . super(name: base'alar8); this.commission 9 commission; ". super(); this.commission 9 commission; .. this.commission 9 commission; super(name: base'alar8); Ans+er: 2 Question: 7< Given: 1. public class Tea" e)ten*s Hava.util..inke*.ist 2. public voi* a**Pla5er$Pla5er p% -. a**$p%# /. ' 5. public voi* co"pete$Tea" opponent% LN "ore co*e here NL ' 8. ' ;. class Pla5er LN "ore co*e here NL '

0hich t+o are true1 $Choose t+o.% A. This code will compile. B. This code demonstrates proper design of an is)a relationship. C. This code demonstrates proper design of a has)a relationship. . A Ea*a programmer using the Team class could remo*e Pla8er obBects from a Team obBect. Ans+er: A2 Question: 7> Click the 3)hibit button. 11. class Pa5loa* 12. private int +ei!ht# 1-. public Pa5loa*$int +t% +ei!ht & +t# ' 1-. public voi* set0ei!ht$"t +% +ei!ht & +# ' 17. public Strin! toStrin! return Inte!er.toStrin!$+ei!ht%# ' 18. ' 1;. 1<. public class TestPa5loa* 1>. static voi* chan!ePa5loa*$Pa5loa* p% 20. LN insert co*e here NL 21. ' 22. 2-. public static voi* "ain$Strin!9: ar!s% 2/. Pa5loa* p & ne+ Pa5loa*$%# 27. p.set0ei!ht$102/%# 28. chan!ePa5loa*$p%# 2;. S5ste".out.println$PThe value of p is QB p%# 2<. ' 2>. ' 0hich state"ent@ place* at line 20@ causes the co*e to print QThe value of p is /20.P1 A. p.set,eight(2#3); B. p.changePa8load(2#3); C. p 9 new Pa8load(2#3); . Pa8load.set,eight(2#3); ". p 9 Pa8load.set,eight(2#3); .. p 9 new Pa8load(); p.set,eight(2#3); Ans+er: A 80. 0hich state"ent$s% are true1 $Choose all that appl5.% A. +as)a relationships alwa8s rel8 on inheritance. B. +as)a relationships alwa8s rel8 on instance *ariables. C. +as)a relationships alwa8s reJuire at least two class t8pes. . +as)a relationships alwa8s rel8 on pol8morphism. ". +as)a relationships are alwa8s tightl8 coupled. Ans+er: )H B is correct. )H A and 2 describe other 55 topics. C is incorrect because a class can ha*e an instance of itself. 3 is incorrect because while has)a relationships can lead to tight coupling: it is b8 no means always the case. 81. Given: class Cli**ers public final voi* flipper$% S5ste".out.println$6Cli**er6%# ' ' public class Cli*lets e)ten*s Cli**ers public voi* flipper$%

S5ste".out.println$6,lip a Cli*let6%# super.flipper$%# ' public static voi* "ain$Strin! 9: ar!s% ne+ Cli*lets$%.flipper$%# ' ' 0hat is the result1 A. .lip a Clidlet B. .lip a Clidder C. .lip a Clidder .lip a Clidlet . .lip a Clidlet .lip a Clidder ". Compilation fails. Ans+er: )H 3 is correct. final methods cannot be o*erridden. )HA@ B@ C@ and 2 are incorrect based on the abo*e. 82. Given: public abstract interface ,robnicate public voi* t+i**le$Strin! s%# ' 0hich is a correct class1 $Choose all that appl5.% A. public abstract class .rob implements .robnicate {
public abstract *oid twiddle('tring s) { } } B. public abstract class .rob implements .robnicate { }

C. public class .rob e(tends .robnicate {


public *oid twiddle(%nteger i) { } }

. public class .rob implements .robnicate {


public *oid twiddle(%nteger i) { } }

". public class .rob implements .robnicate {


public *oid twiddle('tring i) { } public *oid twiddle(%nteger s) { } }

Ans+er: )HB is correct: an abstract class need not implement an8 or all of an interfaceKs methods. 3 is correct: the class implements the interface method and additionall8 o*erloads the twiddle() method. )H A is incorrect because abstract methods ha*e no bod8. C is incorrect because classes implement interfaces the8 donKt e(tend them. 2 is incorrect because o*erloading a method is not implementing it. 8-. Given: class Top public Top$Strin! s% S5ste".out.print$6B6%# ' ' public class Botto"2 e)ten*s Top public Botto"2$Strin! s% S5ste".out.print$626%# ' public static voi* "ain$Strin! 9: ar!s% ne+ Botto"2$6C6%# S5ste".out.println$6 6%# '' 0hat is the result1 A. B B. B

C. B C . BC ". Compilation fails. Ans+er: )H 3 is correct. The implied super() call in Bottom#Ks constructor cannot be satisfied because there isnKt a no)arg constructor in Top. A default: no)arg constructor is generated b8 the compiler onl8 if the class has no constructor defined e(plicitl8. )H A@ B@ C@ and 2 are incorrect based on the abo*e. 8/. Select the t+o state"ents that best in*icate a situation +ith lo+ couplin!. $Choose t+o.% A. The attributes of the class are all pri*ate. B. The class refers to a small number of other obBects. C. The obBect contains onl8 a small number of *ariables. . The obBect is referred to using an anon8mous *ariable: not directl8. ". The reference *ariable is declared for an interface t8pe: not a class. The interface pro*ides a small number of methods. .. %t is unli<el8 that changes made to one class will reJuire an8 changes in another. Ans+er: )H 3 and , are correct. 5nl8 ha*ing access to a small number of methods implies limited coupling. %f the access is *ia a reference of interface t8pe: it ma8 be argued that there is e*en less opportunit8 for coupling as the class t8pe itself is not *isible. 'tating that changes in one part of a program are unli<el8 to cause conseJuences in another part is reall8 the essence of low coupling. There is no such thing as an anon8mous *ariable. >eferring to onl8 a small number of other obBects might impl8 low coupling: but if each obBect has man8 methods: and all are used: then coupling is high. Cariables (attributes) in a class should usuall8 be pri*ate: but this describes encapsulation: rather than low coupling. 5f course: good encapsulation tends to reduce coupling as a conseJuence. )H A@ B@ C and 2 are incorrect based on the preceding treatise. 87. Given: class Cli**er private final voi* flipper$% S5ste".out.println$6Cli**er6%# ' ' public class Cli*let e)ten*s Cli**er public final voi* flipper$% S5ste".out.println$6Cli*let6%# ' public static voi* "ain$Strin! 9: ar!s% ne+ Cli*let$%.flipper$%# '' 0hat is the result1 A. Clidlet B. Clidder C. Clidder Clidlet . Clidlet Clidder ". Compilation fails. Ans+er: )H A is correct. Although a final method cannot be o*erridden: in this case: the method is pri*ate: and therefore hidden. The effect is that a new: accessible: method flipper is created. Therefore: no pol8morphism occurs in this e(ample: the method in*o<ed is simpl8 that of the child class: and no error occurs. )H B@ C@ 2@ and 3 are incorrect based on the preceding.

88. Given: 1. class Plant 2. Strin! !et(a"e$% return 6plant6# ' -. Plant !etT5pe$% return this# ' /. ' 7. class ,lo+er e)ten*s Plant 8. LL insert co*e here ;. ' <. class Tulip e)ten*s ,lo+er ' 0hich state"ent$s%@ inserte* at line 8@ +ill co"pile1 $Choose all that appl5.%
A. .lower getT8pe() { return this; } C. Plant getT8pe() { return this; } Tulip(); } B. 'tring getT8pe() { return !this!; }

. Tulip getT8pe() { return new

Ans+er: )H A@ C@ and 2 are correct. A and 2 are e(amples of co)*ariant returns: i.e.: .lower and Tulip are both subt8pes of Plant. )HB is incorrect: 'tring is not a subt8pe of Plant. 8;. Given: 1. class Rin! 2. protecte* A"pf h# -. ' /. class 0oop e)ten*s Rin! ' 7. class A"pf ' 0hich is true1 $Choose all that appl5.% A. ,oop is)a +mpf and has)a Ling. B. Ling is)a ,oop and has)a +mpf. C. +mpf has)a ,oop and ,oop is)a Ling. . ,oop has)a +mpf and ,oop is)a Ling. ". Ling has)a +mpf and Ling is)a ,oop. Ans+er: )H 2 is correct: ,oop inherits a +mpf from Ling. )H A@ B@ C@ and 3 are incorrect based on the preceding. 8<. Given: 1. class Pro!ra""er 2. Pro!ra""er *ebu!$% return this# ' -. ' /. class SCMP e)ten*s Pro!ra""er 7. LL insert co*e here 8. ' 0hich@ inserte* at line 7@ +ill co"pile1 $Choose all that appl5.%
A. Programmer debug() { return this; } B. 'CEP debug() { return this; } C. 5bBect debug() { return this; } . int debug() { return 0; } ". int debug(int () { return 0; } .. 5bBect debug(int () { return this; }

Ans+er: )H A@ B@ 3@ and , are correct. A and B are e(amples of o*erriding: specificall8: B is an e(ample of o*erriding using a co*ariant return. 3 and , are e(amples of o*erloading. )H C and 2 are incorrect. The8 are illegal o*errides because their return t8pes are incompatible. The8 are illegal o*erloads because their arguments did not change. 8>. Given: class Sber static int 5 & 2# Sber$int )% this$%# 5 & 5 N 2# '

Sber$% 5BB# ' ' class Finor e)ten*s Sber Finor$% super$5%# 5 & 5 B -# ' public static voi* "ain$Strin! 9: ar!s% ne+ Finor$%# S5ste".out.println$5%# '' 0hat is the result1 A. $ B. 6 C. D .7 ". Compilation fails. .. An e(ception is thrown. Ans+er: )H 2 is correct. ;inorKs constructor ma<es an e(plicit call to MberKs 0)arg constructor: which ma<es an e(plicit (this) call to MberKs no)arg constructor: which increments 8: then returns to the 0)arg constructor: which multiples 8 G #: and then returns to ;inorKs constructor: which adds 1 to 8. )H A@ B@ C@ 3@ and , are incorrect based on the preceding. ;0. 0hich state"ent$s% are true1 $Choose all that appl5.% A. Cohesion is the 55 principle most closel8 associated with hiding implementation details. B. Cohesion is the 55 principle most closel8 associated with ma<ing sure that classes <now about other classes onl8 through their AP%s. C. Cohesion is the 55 principle most closel8 associated with ma<ing sure that a class is designed with a single: well)focused purpose. . Cohesion is the 55 principle most closel8 associated with allowing a single obBect to be seen as ha*ing man8 t8pes. Ans+er: )H Answer C is correct. )H A refers to encapsulation: B refers to coupling: and 2 refers to pol8morphism. ;1. Given: 1. class 2o! ' 2. class Bea!le e)ten*s 2o! ' -. /. class Tennel 7. public static voi* "ain$Strin! 9: arfs% 8. Bea!le b1 & ne+ Bea!le$%# ;. 2o! *o!1 & ne+ 2o!$%# <. 2o! *o!2 & b1# >. LL insert co*e here 10. ' 11. ' 0hich@ inserte* at line >@ +ill co"pile1 $Choose all that appl5.% A. Beagle b# 9 (Beagle) dog0; B. Beagle b1 9 (Beagle) dog#; C. Beagle b2 9 dog#; . 4one of the abo*e statements will compile Ans+er: )H A and B are correct. +owe*er: at runtime: A will throw a ClassCast"(ception because dog0 refers to a og obBect: which canKt necessaril8 do Beagle stuff. )H C and 2 are incorrect based on the preceding. ;2. Given the follo+in!@ 1. class O voi* *o1$% ' ' 2. class 4 e)ten*s O voi* *o2$% ' ' -. /. class Chro"e

7. public static voi* "ain$Strin! 9: ar!s% 8. O )1 & ne+ O$%# ;. O )2 & ne+ 4$%# <. 4 51 & ne+ 4$%# >. LL insert co*e here 10. ' 11. ' 0hich@ inserte* at line >@ +ill co"pile1 $Choose all that appl5.% A. (#.do#(); B. (@)(#.do#(); C. ((@)(#).do#(); . 4one of the abo*e statements will compile. Ans+er: )H C is correct. Before 8ou can in*o<e @Ks do# method 8ou ha*e to cast (# to be of t8pe @. 'tatement B loo<s li<e a proper cast but without the second set of parentheses: the compiler thin<s itKs an incomplete statement. )H A@ B and 2 are incorrect based on the preceding. ;-. Given: class Bir* S5ste".out.print$6b1 6%# ' public Bir*$% S5ste".out.print$6b2 6%# ' ' class Kaptor e)ten*s Bir* static S5ste".out.print$6r1 6%# ' public Kaptor$% S5ste".out.print$6r2 6%# ' S5ste".out.print$6r- 6%# ' static S5ste".out.print$6r/ 6%# ' ' class Aa+k e)ten*s Kaptor public static voi* "ain$Strin!9: ar!s% S5ste".out.print$6pre 6%# ne+ Aa+k$%# S5ste".out.println$6ha+k 6%# ' ' 0hat is the result1 A. pre b0 b# r1 r# haw< B. pre b# b0 r# r1 haw< C. pre b# b0 r# r1 haw< r0 r2 . r0 r2 pre b0 b# r1 r# haw< ". r0 r2 pre b# b0 r# r1 haw< .. pre r0 r2 b0 b# r1 r# haw< =. pre r0 r2 b# b0 r# r1 haw< +. The order of output cannot be predicted. %. Compilation fails. Ans+er: )H 2 is correct. 'tatic init bloc<s are e(ecuted at class loading time: instance init bloc<s run right after the call to super() in a constructor. ,hen multiple init bloc<s of a single t8pe occur in a class: the8 run in order: from the top down. )H A@ B@ C@ 3@ ,@ G@ A@ and I are incorrect based on the abo*e.

This Download is from http://www.downloadmela.com The main motto of this website is to provide free download links of ebooks,video tutorials,magazines,previous papers,interview related content. To download more visit the website. If you like our services please help us in ways. !.Donating money. "lease go through the link for donating http://www.downloadmela.com/donate.html .Tell about this website to your friends,relatives.
Than<s for downloading. "nBo8 the reading.

You might also like