SCJP Sun Certified Programmer for Java 6 Study Guide - Self Test

Flash cards based on Kathy Sierra & Bert Bates SCJP Study Guide

5 cards   |   Total Attempts: 188
  

Cards In This Set

Front Back
Which is true?
A. "X extends Y" is correct if and only if X is a class and Y is an interface.
B. "X extends Y" is correct if and only if X is an interface and Y is a class.
C. "X extends Y" is correct if X and Y are either both classes or both interfaces.
D. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
C is correct.
A is incorrect because classes implement interfaces, they don't extend them. B is incorrect because interfaces only inherit from other interfaces. D is incorrect based on the preceding rulings.
Which method names follow the JavaBeans standard? (Choose all that apply).

A. addSize
B. getCust
C. deleteRep
D. isColorado
E. putDimensions
B and D use the valid prefixes 'get' and 'is'.
A is incorrect because add can be used only with Listener methods. C and E are incorrect because 'delete' and 'put' are not JavaBeans name prefixes.
Given:
1. class Voop {
2. public static void main (String [] args) {
3. doStuff(1);
4. doStuff(1,2);
5. }
6. //Insert code here.
7. }

Which inserted independently at line 6, will compile? (Choose all that apply)

A. static void doStuff(int... doArgs) {}
B. static void doStuff(int[] doArgs) {}
C. static void doStuff(int doArgs...) {}
D. static void doStuff(int x, int... doArgs) {}
A and E are valid var-agrs syntax.
B and C are invalid var-args syntax, and D is invalid because the var-arg must be the last of a method's arguments.
Given:
1. enum Animals {
2. DOG("woof"), CAT("meow"), FISH("burble");
3. String sound;
4. Animals(String s ){ sound =s;}
5. }
6. class TestEnum {
7. static Animals a;
8. public static void main (String[] args) {
9. System.out.println (a.Dog.sound + "" + a.FISH.sound);
10. }
11. }

What is the result?

A. woof burble
B. Multiple compilation errors.
C. Compilation fails due to an error on line 2.
D. Compilation fails due to an error on line 3.
E. Compilation fails due to an error on line 4.
E. Compilation fails due to an error on line 9.
A is correct; enums can have constructors and variables.
B, C, D, E, and F are incorrect; these lines all use correct syntax.
Given two files:
1. package pkgA;
2. public class Foo {
3. int a = 5;
4. protected int b = 6;
5. public int c = 7;
6. }

3. package pkgB;
4. import pkgA.*;
5. public class Baz {
6. public static void main ( String [] args){
7. Foo f = new Foo();
8. System.out.print(" " + f.a);
9. System.out.print(" " + f.b);
10. System.out.print(" " + f.c);
11. }
12. }

What is the restult? (Choose all that apply)

A. 5 6 7
B. 5 followed by an exception
C. Compilation fails with an error on line 7
D. Compilation fails with an error on line 8
E. Compilation fails with an error on line 9
F. Compilation fails with an error on line 10

D and E are correct. Variable a has default access, so it cannot be accessed from outside the package. Vairable b has protected access in pkgA.
A, B, C, and F are incorrect based on the above information.