Lefora Free Forum
138 views

SCJP 5.0 Review

Page 1
posts 1–20 of 20
novice - founder
34 posts

God bless our examiness. Let's review together guys!

__________________
ang jologs
novice - founder
34 posts
What is the output of this code block?

public class Foo {
void g(double d) {
System.out.println("d");
}
void g(Number num) {
System.out.println("num");
}
void g(Object obj) {
System.out.println("obj");
}
public static void main(String[] args) {
new Foo().g(10);
new Foo().g(new Integer(10));
}
}
__________________
ang jologs
novice - founder
34 posts

Answer:

d
num

Why?
First, the value 10 is an int which superceeds double values, so it is also considered a double.
Second, the Number class is the abstract class of BigInteger, BigDecimal, Integer, Long, so instead of entering the Object obj overloaded method, it enters the Number num since Integer IS-A Number, and Number IS-A n Object

__________________
ang jologs
rookie - member
2 posts

this code is an example that describes closely to Wrapper objects. tama ba?

novice - founder
34 posts
This code is almost completely useless when you are doing Enterprise Development. First, you dont make confusing overloaded method parameters, and second, you always have Mr. JUnit test to help you out. Sometimes SCJP questions are stupid, they're just there to make our lives harder (and make our value better)
__________________
ang jologs
novice - member
44 posts

tanong mo sagot mo. hahaha

__________________
ang laseng.
novice - member
44 posts

kalokohan to.

Given:

1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower {}

Which statement(s), inserted at line 6, will compile? (Choose all that apply.)

A. Flower getType() { return this; }

B. String getType() { return "this"; }

C. Plant getType() { return this; }

D. Tulip getType() { return new Tulip() ;}

anu sagot?

__________________
ang laseng.
novice - member
44 posts

kalokohan #2.

eto pang isa. ibibigay ko sagot pag may sumagot na :-s

Given:

1. class Programmer {
2. Programmer debug() { return this; }
3. }
4. class SCJP extends Programmer {
5. // insert code here
6. }

Which, inserted at line 5, will compile? (Choose all that apply.)

A. Programmer debug() { return this; }

B. SCJP debug() { return this; }

C. Object debug() { return this; }

D. int debug() { return 1; }

E. int debug(int x) { return 1; }

F. Object debug (int x) { return this; }

__________________
ang laseng.
novice - founder
34 posts

A, B, E and F...

Pero A and B are not compatible, it means, only one can exist...

E and F are also not compatible so only one of the two c an exist in the code block... (method overloading)

__________________
ang jologs
novice - member
44 posts

class is an object.

Classes extends Object

so>>> C. Object debug() { return this; } //pwede. magcocompile.
int debug() { return 1; } //khet nmn ilagay mo to don magcocompile pa ren e.

if we insert any/all of the choices the code will still compile.
tama nga. sabe sa reviewer the answer is ABEF.

__________________
ang laseng.
novice - member
36 posts

ala bang choice na "All of the Above" sa question #2? all choices will compile nman e..hehehe...

novice - member
36 posts

as for kalokohan question #1, answer ku are A and B and C...

novice - member
44 posts

question number #1 mali yung B. hehe. sabe sa reviewer. amf manlito ba.

__________________
ang laseng.
novice - member
44 posts

basta magcompile. wala nmn tayong pake kung anu gusto nyang gawen e. basta nagcompile. yun lang nmn tinatanong nya e.

__________________
ang laseng.
novice - member
36 posts

huh? ang question is, kung anu ang statement na if inserted, mag cocompile ang code...and choice B is legal...it may not be logically sound, pero it will compile...

novice - member
44 posts

oo nga e. pang asar tong reviewer e.

__________________
ang laseng.
novice - member
36 posts

tama c zai...ala muna dpat dev mentality...dpat concepts lng lahat...ang hina ku pa nman sa nitty gritty concepts ng java...pfts...gus2 ku pa nmang kumuha within the next couple of months..pft...

novice - member
44 posts

basta. warla kame ni sierra.

__________________
ang laseng.
novice - member
36 posts

huh?

guest poster

???

Page 1
posts 1–20 of 20

This Topic Is Locked To Guest Posts

It's been a while since this topic was active, if you'd like to get it going again, please post as a registered member

join now