Java SCJP 8
Java SCJP Cert Fragen
Java SCJP Cert Fragen
-
- 1 / 200
-
Flashcards
Which code lines compile?
Which code lines compile?
Which are legal var-arg declarations?
Which are legal var-arg declarations?
What is the result of following code:
1. class Test {
2. Test t1 = new Test();
3. Test t2 = new Test();
4. if ( !t1.equals(t2) )
5. System.out.println("they're not equal");
4. if ( t1 instanceof Object )
5. System.out.println("t1's an Object");
6. }
7. }
A class can...?
Mark the correct rules for overriding a method.
Mark the correct rules for overriding a method.
Mark the correct rules for overriding a method.
Mark the correct rules for overriding a method.
What is the result?
1. class Animal {
2. void makeNoise() { System.out.println( „generice noise“ ); }
3. }
4. class Doc extends Animal {
5. void makeNoise() { System.out.println( “Bark”); }
6. void playDead() { System.out.println( “roll over”); }
7. }
8. class DocTest {
9. public static void main(String[] args) {
10. Animal animal = new Animal();
11. Doc d = (Doc) animal;
12. d.makeNoise();
13. }
14. }
Is it valid return?
1. public int foo() {
2. char c= 'c‘;
3. return c;
4. }
What is the result?
1. class Animal {
2. void makeNoise() { System.out.println( „generice noise“ ); }
3. }
4. class Doc extends Animal {
5. Doc(String s) {
6. super();
7. }
8. void makeNoise() { System.out.println( “Bark”); }
9. void playDead() { System.out.println( “roll over”); }
10. }
11. class DocTest {
12. public static void main(String[] args) {
13. Doc d= new Doc();
14. d.makeNoise();
13. }
14. }
What is the result?
1. package path.pkg.a
2. class Animal {
3. void makeNoise() { System.out.println( „generice noise“ ); }
4. }
5.
6. package path.pkg.b
7. class Doc extends Animal {
8. Doc() {
9. super();
10. }
11. void makeNoise() { System.out.println( “Bark”); }
12. void playDEad() { Syste.out.println( “roll over”); }
13. }
14.
15. package path.pkg.b
16. class DocTest {
17. public static void main(String[] args) {
18. Doc doc = new Doc();
19. doc.makeNoise();
20. }
21. }
What is the result?
1. package path.pkg.a
2. class Animal {
3. void makeNoise() { System.out.println( „generice noise“ ); }
4. }
5.
6. package path.pkg.b
7. class Doc extends Animal {
8. private Doc() {
9. super();
10. }
11. void makeNoise() { System.out.println( “Bark”); }
12. void playDEad() { Syste.out.println( “roll over”); }
13. }
14.
15. package path.pkg.b
16. class DocTest {
17. public static void main(String[] args) {
18. Doc doc = new Doc();
19. doc.makeNoise();
20. }
21. }
What is the result?
1. package path.pkg.a
2. class Animal {
3. Animal(){
4. System.out.println(„Hellow Animal“);
5. }
6. void makeNoise() { System.out.println( „generice noise“ ); }
7. }
8.
9. package path.pkg.b
10. class Doc extends Animal {
11. Doc() {
12. super();
13. }
14. void makeNoise() { System.out.println( “Bark”); }
15. void playDEad() { Syste.out.println( “roll over”); }
16. }
17.
18. package path.pkg.b
19. class DocTest {
20. public static void main(String[] args) {
21. Doc doc = new Doc();
22. doc.makeNoise();
23. }
24. }
Welche Aussagen sind richtig?
What ist the result?
Given:
3. class Dog {
4. public void bark() { System.out.print( “woof “); }
5. }
6. class Hound extends Dog {
7. public void sniff() { System.out.print(“sniff “); }
8. public void bark() { System.out.print(“howl “); }
9. }
10. public void DogShow {
11. public static void main(String… args) { new DogShow().go(); }
12. void go() {
13. new Hound().bark();
14. ((Dog) new Hound()).bark();
15. ((Dog) new Hound()).sniff();
16. }
17. }
(SCPJ 6, Seite175)
What is the restul?
Given:
public class Redwood extends Tree {
public static void main(String[] args) {
new Redwood().go();
}
void go() {
go2(new Tree(), new Redwood());
go2( (Redwood) new Tree(), new Redwood());
}
void go2(Tree t1, Redwood r1) {
Redwood r2 = (Redwood) t1;
Tree t2 = (Tree) r1;
}
class Tree { }
(SCJP 6, page 176)
What is the restul?
Given:
3. class Mammal {
4. String name = “furry “;
5. String makeNoise() { return “generic noise”; }
6. }
7. class Zebra extends Mammal {
8. String name = “stripes “;
9. String makeNoise() { return “bray”; }
10. }
11. public class ZooKeeper {
12. public static void main(String[] args) { new ZooKeeper().go(); }
13. void go() {
14. Mammal m = new Zebra();
15. System.out.println( m.name + “ “ + m.makeNoise() );
16. }
17. }
(SCJP 6, page 179)
What is the restul?
Given:
3. class A { }
4. class B extends A { }
5. public class ComingThru {
6. static String s = “-“;
7. public static void main(String[] args) {
8. A[] aa = new A[2];
9. B[] bb = new B[2];
10. sifter(aa);
11. sifter(bb);
12. sifter(7);
13. System.out.println(s);
14. }
15. static void sifter(A[]… a2) { s += “1”; }
16. static void sifter(B[]… b2) { s += “2”; }
17. static void sifter(B[] b1) { s += “3”; }
18. static void sifter(Object o) { s += “4”; }
19. }
(SCJP 6, page 179)
Stack/Heap: Witch is true?
Assingment: Which result ist correct?
class Bird {
{ System.out.print("b1 "); };
static { System.out.print("b2 "); };
public Bird() { System.out.print("b3 "); };
}
class Raptor extends Bird {
static { System.out.print("r1 "); };
public Raptor() { System.out.print("r2 "); };
{ System.out.print("r3 "); };
static { System.out.print("r4 "); };
}
public class Hawk extends Raptor {
public static void main(String... args){
System.out.print("pre ");
new Hawk();
System.out.print("hawk ");
}
}
(SCJP 6, page 281)
Which are ture?
Give:
3. public class Bridge {
4. public enum Suits{
5. CLUBS(20), DIAMONDS(20), HEARTS(30), SPADES(30),
6. NOTRUMP(40) { public int getValue(int bid) {
return ((bid-1)*30)+40; } };
7. Suits(int points) { this.points = points; }
8. private int points;
9. public int getValue(int bid) { return points * bid; }
10. }
11. public static void main(String[] args){
12. System.out.println(Suits.NOTRUMP.getValue(3));
13. System.out.println(Suits.SPADES + " " + Suits.SPADES.points );
14. System.out.println(Suits.values());
15. }
16. }
(SCJP 6, page 281)
When line 16 is reached, how many objects will be eligible for garbage collection?
Given:
3. public class Beta { }
4. public class Alpha {
5. static Beta b1;
6. Beta b2;
7. }
8. public class Tester {
9. public static void main( String [] args ) {
10. Beta b1 = new Beta();
11. Alpha a1 = new Alpha();
12. a1.b1 = b1;
13. a1.b2 = b1;
14. a2.b2 = b2;
15. a1 = null; a2 = null; b2 = null;
16. // do stuff
17. }
18. }
(SCJP 6, page 284)
1
What is the result?
Given:
3. class Box {
4. int size;
5. Box(int s) { size = s; }
6. }
7. public class Laser {
8. public static void main(String[] args) {
9. Box b1 = new Box(5);
10. Box[] ba = og(b1, new Box(6) );
11. ba[0] = b1;
12. for(Box b : ba) System.out.print( b.size + “ “ );
13. }
14. static Box[] go(Box b1, Box b2) {
15. b1.size. = 4;
16. Box[] ma = {b2, b1};
17. return ma;
18. }
(SCPJ 6, page 285)