Sei sulla pagina 1di 8

Prparation la certification JAVA

Correction du Test blanc N1


Nom & Prnom : .....
QUESTION 1
You want a class to have access to members of another class in the same package. Which
is the most restrictive access that accomplishes this objective?
A. public
B. private
C. protected
D. transient
E. default access
Answer:
QUESTION 2
Given:
1. public interface Foo {
2. int k = 4;
3. }
Which are equivalent to line 2?
A. final int k = 4;
B. public int k = 4;
C. static int k = 4;
D. abstract int k = 4;
E. volatile int k = 4;
F. protected int k = 4;
Answer:
QUESTION 3
Given:
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.println("x = " + x);
5. }
6. }
1

What is the result?


A. x = 0
B. x = 42
C. Compilation fails because of an error in line 2 of class Test2.
D. Compilation fails because of an error in line 3 of class Test1.
E. Compilation fails because of an error in line 4 of class Test2.
Answer:
QUESTION 4
Which are valid declarations within an interface definition?
A. void methoda();
B. public double methoda();
C. public final double methoda();
D. static void methoda(double d1);
E. protected void methoda(double d1);
Answer:
QUESTION 5
You want to limit access to a method of a public class to members of the same class.
Which access accomplishes this objective?
A. public
B. private
C. protected
D. transient
E. default access
Answer:
QUESTION 6
Given:
1. public abstract class Test {
2. public abstract void methodA();
3.
4. public abstract void methodB()
5. {
6. System.out.println("Hello");
7. }
8. }
Which change(s), independently applied, allow this code to compile?
A. Add a method body to methodA.
B. Replace lines 5 - 7 with a semicolon (";").
C. Remove the abstract qualifier from the declaration of Test.
D. Remove the abstract qualifier from the declaration of methodA.
E. Remove the abstract qualifier from the declaration of methodB.
Answer:

QUESTION 7
You want subclasses in any package to have access to members of a superclass. Which is
the most restrictive access that accomplishes this objective?
A. public
B. private
C. protected
D. transient
E. default access
Answer:
QUESTION 8
Which of these are valid declaration of the main() method?
(a) static void main(String args[]) {/* */}
(b) public static int main(String args[]) {/* */}
(c) public static void main(String args) {/* */}
(d) final static public void main(String[] arguments) {/* */}
(e) public int main(String args[], int argc) {/* */}
(f) public void main(String args[]) {/* */}
Answer:
QUESTION 9
Which are valid declarations? (Choose all that apply.)
A. int $x;
B. int 123;
C. int _123;
D. int #dim;
E. int %percent;
F. int *divide;
G. int central_sales_region_Summer_2005_gross_sales;
Answer:
QUESTION 10
Given:
1. enum A { A }
2. class E2 {
3. enum B { B }
4. void C() {
5. enum D { D }
6. }
7. }
Which statements are true? (Choose all that apply.)
A. The code compiles.
B. If only line 1 is removed the code compiles.
C. If only line 3 is removed the code compiles.
D. If only line 5 is removed the code compiles.
3

E. If lines 1 and 3 are removed the code compiles


F. If lines 1, 3 and 5 are removed the code compiles.
Answer:
QUESTION 11
Given the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A. interface Base2 implements Base { }
B. abstract class Class2 extends Base {
public boolean ml() { return true; } }
C. abstract class Class2 implements Base { }
D. abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E. class Class2 implements Base {
boolean m1( ) { return false; }
byte m2(short s) { return 42; } }
Answer:

QUESTION 12
Which declare a compilable abstract class? (Choose all that apply.)
A. public abstract class Canine { public Bark speak(); }
B. public abstract class Canine { public Bark speak() { } }
C. public class Canine { public abstract Bark speak(); }
D. public class Canine abstract { public abstract Bark speak(); }
Answer:
QUESTION 13
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...) { }
4

D. static void doStuff(int... doArgs, int y) { }


E. static void doStuff(int x, int... doArgs) { }
Answer:
QUESTION 14
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
F. Compilation fails due to an error on line 9
Answer:
QUESTION 15
Select the size of an int type
A. 32 bytes
B. 16 bits
C. 32 bits
D. 16 bytes
Answer:
QUESTION 16
Select default value of boolean type
A. true
B. false
C. 0
D. 1
Answer:
5

QUESTION 17
Please select floating point types
A. byte
B. int
C. double
D. short
E. long
F. float
Answer:
QUESTION 18
The private modifier can be applied to ...
A. A variable
B. A method
C. A top level class
D. All of the above
Answer:
QUESTION 19
Please select invalid java keywords
A. ifdef
B. sizeof
C. goto
Answer:
QUESTION 20
What keyword is used to prevent an object from being serialized?
A.private
B.volatile
C.protected
D.transient
E.None of the above
Answer:
QUESTION 21
A Java Bean component has the following field:
private Boolean enabled;
Which two pairs of method declarations follow the JavaBean standard for accessing
this fields?
A. public void setEnabled ( Boolean enabled)
public Boolean getEnabled ( )
B. public void setEnabled ( Boolean enabled)
public void isEnabled ( )
6

C. public void setEnabled ( Boolean enabled)


public Boolean isEnabled ( )
Answer:
QUESTION 22
public abstract class Shape{
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x,int y){
this.x=x;
this.y=y;
}
}
Which classe(s) use the Shape class correctly?
A. public class Circle implements Shape { private int radius; }
B. public abstract class Circle extends Shape { private int radius; }
C. public class Circle extends Shape { private int radius; public void draw ( ); }
D. public abstract class Circle implements Shape {
private int radius; public void draw ( );
}
E. public class Circle extends Shape {private int radius; public void draw () { } }
F. public ABSTRACT class Circle implements Shape {
private int radius;
public void draw ( ) { }
}
Answer:
QUESTION 23
Consider the following line of code:
int[] x = new int[25];
After execution, which statements are true? (Choose all that apply.)
A. x[24] is 0
B. x[24] is undefined
C. x[25] is 0
D. x[0] is null
E. x.length is 25
Answer:
QUESTION 24
What is the range of values that can be assigned to a variable of type short?
A. Depends on the underlying hardware
B. 0 through 216 1
C. 0 through 232 1
7

D. 215 through 215 1


E. 231 through 231 1
Answer:
QUESTION 25
To make a variable defined in a class accessible only to methods defined in the classes in
same package, which of the following keyword should be used. Select the one correct
answer.
A. By using the keyword package before the variable.
B. By using the keyword private before the variable.
C. By using the keyword protected before the variable.
D. By using the keyword public before the variable.
E. The variable should not be preceded by any of the above mentioned keywords.
Answer:

Potrebbero piacerti anche