Lefora Free Forum
58 views

SCJP 5.0 Trick Questions

Page 1
posts 1–6 of 6
novice - member
36 posts

Try nyu to(galing kay sierra at bates to):

Given:
class Top {
public Top(String s) { System.out.print("B"); }
}
public class Bottom2 extends Top {
public Bottom2(String s) { System.out.print("D"); }
public static void main(String [] args) {
new Bottom2("C");
System.out.println(" ");
}
}
What is the result?
A. BD
B. DB
C. BDC
D. DBC
E. Compilation fails.

Anu sagut? hehehe...

novice - member
44 posts

compilation fails >:)

kase pag tinawag yung constructor ni Bottom2 e tatawgin nya yung super();
yung constructor ni Top na walang argument. since wla non, compilation fails ^^

__________________
ang laseng.
novice - member
36 posts

may tama ka...hehehe...mag po-post aku ng mga ganito para ma review ka rin..hehehe...

novice - member
36 posts

eto pa isa:

what is the output of this code:

public class IntTest {

public static void main(String[] args) {
byte a = 10;
byte b = 5;

byte c = a + b;

System.out.println(c);
}

}

novice - member
36 posts

at ito pa:

Given:
class Alien {
String invade(short ships) { return "a few"; }
String invade(short... ships) { return "many"; }
}
class Defender {
public static void main(String [] args) {
System.out.println(new Alien().invade(7));
} }
What is the result?
A. many
B. a few
C. Compilation fails.
D. The output is not predictable.
E. An exception is thrown at runtime.

novice - member
36 posts

one more:

class Mixer {
Mixer() { }
Mixer(Mixer m) { m1 = m; }
Mixer m1;
public static void main(String[] args) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2); m3.go();
Mixer m4 = m3.m1; m4.go();
Mixer m5 = m2.m1; m5.go();
}
void go() { System.out.print("hi "); }
}
What is the result?
A. hi
B. hi hi
C. hi hi hi
D. Compilation fails
E. hi, followed by an exception
F. hi hi, followed by an exception

Page 1
posts 1–6 of 6

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