God bless our examiness. Let's review together guys!
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));
}
}
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
this code is an example that describes closely to Wrapper objects. tama ba?
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?
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; }
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)
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.
ala bang choice na "All of the Above" sa question #2? all choices will compile nman e..hehehe...
as for kalokohan question #1, answer ku are A and B and C...
question number #1 mali yung B. hehe. sabe sa reviewer. amf manlito ba.
basta magcompile. wala nmn tayong pake kung anu gusto nyang gawen e. basta nagcompile. yun lang nmn tinatanong nya e.
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...
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...
???
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