Showing posts with label DUMPS. Show all posts
Showing posts with label DUMPS. Show all posts

JAVA@COFFEE


JAVA TUTORIALS


JAVA DUMPS
TIPS



JAVA DUMPS 19 (SCJP)

QUESTION NO: 6

Which statement is true?

A. Memory is reclaimed by calling Runtime.gc().

B. Objects are not collected if they are accessible from live threads.

C. Objects that have finalize() methods are never garbage collected.

D. Objects that have finalize() methods always have their finalize() methods called before

the program ends.

E. An OutOfMemory error is only thrown if a single block of memory cannot be found

that is large enough for a particular requirement.

Answer: B


 

QUESTION NO: 7

Given:

1. class A {

2. A() { }

3. }

4.

5. class B extends A {

6. }

Which two statements are true? (Choose two)

A. Class B's constructor is public.

B. Class B's constructor has no arguments.

C. Class B's constructor includes a call to this().

D. Class B's constructor includes a call to super().

Answer: B, D


 

QUESTION NO: 8

Given:

11. int i = 1,j = 10;

12. do {

13. if(i>j) {

14. break;

15. }

16. j--;

17. } while (++i <5);

18. System.out.println("i =" +i+" and j = "+j);

What is the result?

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 5 and j = 6

E. i = 6 and j = 6

Answer: D


 

QUESTION NO: 9

Which statement is true?

A. Assertions can be enabled or disabled on a class-by-class basis.

B. Conditional compilation is used to allow tested classes to run at full speed.

C. Assertions are appropriate for checking the validity of arguments in a method.

D. The programmer can choose to execute a return statement or to throw an exception if

an assertion fails.

Answer: A


 

QUESTION NO: 10

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: E

JAVA DUMPS 18 (SCJP)

QUESTION NO: 1

Given:

1. public class Test {

2. public static void main(String args[]) {

3. class Foo {

4. public int i = 3;

5. }

6. Object o = (Object)new Foo();

7. Foo foo = (Foo)o;

8. System.out.println("i = " + foo.i);

9. }

10. }

What is the result?

A. i = 3

B. Compilation fails.

C. A ClassCastException is thrown at line 6.

D. A ClassCastException is thrown at line 7.

Answer: A


 

QUESTION NO: 2

Which two cause a compiler error? (Choose two)

A. float[] = new float(3);

B. float f2[] = new float[];

C. float[] f1 = new float[3];

D. float f3[] = new float[3];

E. float f5[] = { 1.0f, 2.0f, 2.0f };

F. float f4[] = new float[] { 1.0f. 2.0f. 3.0f};

Answer: A, B

QUESTION NO: 3

Given:

11. int i =1,j =10;

12. do {

13. if(i++> --j) {

14. continue;

15. }

16. } while (i <5);

17. System.out.println("i = " +i+ "and j = "+j);

What is the result?

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 5

D. i = 5 and j = 6

E. i = 6 and j = 6

Answer: D


 

QUESTION NO: 4

Given:

1. class Test {

2. private Demo d;

3. void start() {

4. d = new Demo();

5. this.takeDemo(d);

6. }

7.

8. void takeDemo(Demo demo) {

9. demo = null;

10. demo = new Demo();

11. }

12. }

When is the Demo object, created on line 3, eligible for garbage collection?

A. After line 5.

B. After line 9.

C. After the start() method completes.

D. When the takeDemo() method completes.

E. When the instance running this code is made eligible for garbage collection.

Answer: E

QUESTION NO: 5

Given:

1. interface Animal {

2. void soundOff();

3. }

4.

5. class Elephant implements Animal {

6. public void soundOff() {

7. System.out.println("Trumpet");

8. }

9. }

10.

11. class Lion implements Animal {

12. public void soundOff() {

13. System.out.println("Roar");

14. }

15. }

16.

17. class Alpha1 {

18. static Animal get( String choice ) {

19. if ( choice.equalsIgnoreCase( "meat eater" )) {

20. return new Lion();

21. } else {

22. return new Elephant();

23. }

24. }

25. }

Which compiles?

A. new Animal().soundOff();

B. Elephant e = new Alpha1();

C. Lion 1 = Alpha.get("meat eater");

D. new Alpha1().get("veggie").soundOff();

Answer: D

JAVA DUMPS 17 (SCJP)

QUESTION NO: 92

Given:

1. abstract class AbstractIt {

2. abstract float getFloat();

3. }

4. public class AbstractTest extends AbstractIt {

5. private float f1 = 1.0f;

6. private float getFloat() { return f1; }

7. }

What is the result?

A. Compilation succeeds.

B. An exception is thrown.

C. Compilation fails because of an error at line 2.

D. Compilation fails because of an error at line 6.

Answer: D


 

QUESTION NO: 93

Which four can be thrown using the throw statement? (Choose four)

A. Error

B. Event

C. Object

D. Throwable

E. Exception

F. RuntimeException

Answer: A, D, E, F


 

QUESTION NO: 94

What produces a compiler error?

A. class A {

public A(int x) {}

}

B. class A {

}

class B extends A {

B() {}

}

C. class A {

A() {}

}

class B {

public B() {}

}

D. class Z {

public Z(int) {}

}

class A extends Z {

}

Answer: D


 

QUESTION NO: 95

Given:

11. for( int i = min; i <max; i++) {

12. System.out.println(i);

13. }

If min and max are arbitrary integers, what gives the same result?

A. init i = min;

while( i < max ) {

}

B. int i = min;

do

System.out.println(i++);

} while( i< max );

C. for (int i=min; i<max; System.out.println(++I));

D. for (int i=; i++<max; System.out.println(i));

Answer: B

JAVA DUMPS 16 (SCJP)

QUESTION NO: 85

Given:

12. float f[][][] = new float[3][][];

13. float f0 = 1.0f;

14. float[][] farray = new float[1][1];

What is valid?

A. f[0] = f0;

B. f[0] = farray;

C. f[0] = farray[0];

D. f[0] = farray[0][0];

Answer: B


 

QUESTION NO: 86

Given:

11. for (int i =0; i < 4; i +=2) {

12. System.out.print(i + "");

13. }

14. System.out.println(i);

What is the result?

A. 0 2 4

B. 0 2 4 5

C. 0 1 2 3 4

D. Compilation fails.

E. An exception is thrown at runtime.

Answer: D


 

QUESTION NO: 87

Given:

12. void start() {

13. A a = new A();

14. B b = new B();

15. a.s(b);

16. b = null;

17. a = null;

18. System.out.printIn("start completed");

19. }

When is the B object, created in line 14, eligible for garbage collection?

A. After line 16.

B. After line 17.

C. After line 18 (when the methods ends).

D. There is no way to be absolutely certain.

E. The object is NOT eligible for garbage collection.

Answer: C


 

QUESTION NO: 88

Given:

1. public class Exception Test {

2. class TestException extends Exception {}

3. public void runTest() throws TestException {}

4. public void test() /* Point X */ {

5. runTest();

6. }

7. }

At Point X on line 4, which code is necessary to make the code compile?

A. No code is necessary.

B. throws Exception

C. catch ( Exception e )

D. throws RuntimeException

E. catch ( TestException e)

Answer: B


 

QUESTION NO: 89

Given:

11. int i = 0;

12. while (true) {

13. if(i==4) {

14. break;

15. }

16. ++i;

17. }

18. System.out.println("i="+i);

What is the result?

A. i = 0

B. i = 3

C. i = 4

D. i = 5

E. Compilation fails.

Answer: C


 

QUESTION NO: 90

Given:

11. try {

12. int x = 0;

13. int y = 5 / x;

14. } catch (Exception e) {

15. System.out.println("Exception");

16. } catch (ArithmeticException ae) {

17. System.out.println("Arithmetic Exception");

18. }

19. System.out.println("finished");

What is the result?

A. finished

B. Exception

C. Compilation fails.

D. Arithmetic Exception

Answer: C


 

QUESTION NO: 91

Given:

1. public class Test { }

What is the prototype of the default constructor?

A. Test()

B. Test(void)

C. public Test()

D. public Test(void)

E. public void Test()

Answer: A

JAVA DUMPS 15 (SCJP)

QUESTION NO: 78

Given:

11. public class Test {

12. public void foo() {

13. assert false;

14. assert false;

15. }

16. public void bar(){

17. while(true){

18. assert false;

19. }

20. assert false;

21. }

22. }

What causes compilation to fail?

A. Line 13

B. Line 14

C. Line 18

D. Line 20

Answer: D


 

QUESTION NO: 79

Which statement is true?

A. Programs will not run out of memory.

B. Objects that will never again be used are eligible for garbage collection.

C. Objects that are referred to by other objects will never be garbage collected.

D. Objects that can be reached from a live thread will never be garbage collected.

E. Objects are garbage collected immediately after the system recognizes they are

eligible.

Answer: D


 

QUESTION NO: 80I

n which two cases does the compiler supply a default constructor for class A? (Choose

two)

A. class A {

}

B. class A {

public A() {}

}

C. class A {

public A(int x) {}

}

D. class Z {}

class A extends Z {

void A() {}

}

Answer: A, D


 

QUESTION NO: 81

Given:

1. public class ReturnIt {

2. return Type methodA(byte x, double y) {

3. return (short)x / y * 2;

4. }

5. }

What is the narrowest valid returnType for methodA in line2?

A. int

B. byte

C. long

D. short

E. float

F. double

Answer: F


 

QUESTION NO: 82

Given:

1. public class Outer{

2. public void someOuterMethod() {

3. // Line 3

4. }

5. public class Inner{}

6. public static void main( String[]argv ) {

7. Outer o = new Outer();

8. // Line 8

9. }

10. }

Which instantiates an instance of Inner?

A. new Inner(); // At line 3

B. new Inner(); // At line 8

C. new o.Inner(); // At line 8

D. new Outer.Inner(); // At line 8

Answer: A


 

QUESTION NO: 83

What allows the programmer to destroy an object x?

A. x.delete()

B. x.finalize()

C. Runtime.getRuntime().gc()

D. Explicitly setting the object's reference to null.

E. Ensuring there are no references to the object.

F. Only the garbage collection system can destroy an object.

Answer: F


 

QUESTION NO: 84

Given:

11. int x = 1, y =6;

12. while (y--) {

13. x++;

14. }

15. System.out.println("x =" + x + "y =" +y);

What is the result?

A. x = 6 y = 0

B. x = 7 y = 0

C. x = 6 y = -1

D. x = 7 y = -1

E. Compilation fails.

Answer: D

JAVA DUMPS 14 (SCJP)

QUESTION NO: 72

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: C


 

QUESTION NO: 73

Given:

1. class Exc0 extends Exception { }

2. class Exc1 extends Exc0 { }

3. public class Test {

4. public static void main(String args[]) {

5. try {

6. throw new Exc1();

7. } catch (Exc0 e0) {

8. System.out.println("Ex0 caught");

9. } catch (Exception e) {

10. System.out.println("exception caught");

11. }

12. }

13. }

What is the result?

A. Ex0 caught

B. exception caught

C. Compilation fails because of an error at line 2.

D. Compilation fails because of an error at line 6.

Answer: A


 

QUESTION NO: 74

Given:

20. public float getSalary(Employee e) {

21. assert validEmployee(e);

22. float sal = lookupSalary(e);

23. assert (sal>0);

24. return sal;

25. }

26. private int getAge(Employee e) {

27. assert validEmployee(e);

28. int age = lookupAge(e);

29. assert (age>0);

30. return age;

31. }

Which line is a violation of appropriate use of the assertion mechanism?

A. line 21

B. line 23

C. line 27

D. line 29

Answer: A


 

QUESTION NO: 75

Given:

1. public class A {

2. void A() {

3. System.out.println("Class A");

4. }

5. public static void main(String[] args) {

6. new A();

7. }

8. }

What is the result?

A. Class A

B. Compilation fails.

C. An exception is thrown at line 2.

D. An exception is thrown at line 6.

E. The code executes with no output.

Answer: E


 

QUESTION NO: 76

Given:

1. class Bar { }

1. class Test {

2. Bar doBar() {

3. Bar b = new Bar();

4. return b;

5. }

6. public static void main (String args[]) {

7. Test t = new Test();

8. Bar newBar = t.doBar();

9. System.out.println("newBar");

10. newBar = new Bar();

11. System.out.println("finishing");

12. }

13. }

At what point is the Bar object, created on line 3, eligible for garbage collection?

A. After line 8.

B. After line 10.

C. After line 4, when doBar() completes.

D. After line 11, when main() completes.

Answer: C


 

QUESTION NO: 77

Given:

1. interface Beta {}

2.

3. class Alpha implements Beta {

4. String testIt() {

5. return "Tested";

6. }

7. }

8.

9. public class Main1 {

10. static Beta getIt() {

11. return new Alpha();

12. }

13. public static void main( String[] args ) {

14. Beta b = getIt();

15. System.out.println( b.testIt() );

16. }

17. }

What is the result?

A. Tested

B. Compilation fails.

C. The code runs with no output.

Answer: B

JAVA DUMPS 13(SCJP)

Given:

1. class Super {

2. public int i = 0;

3.

4. public Super(String text) {

5. i = 1;

6. }

7. }

8.

9. public class Sub extends Super {

10. public Sub(String text) {

11. i = 2;

12. }

13.

14. public static void main(String args[]) {

15. Sub sub = new Sub("Hello");

16. System.out.println(sub.i);

17. }

18. }

What is the result?

A. 0

B. 1

C. 2

D. Compilation fails.

Answer: D


 

QUESTION NO: 68

Given:

11. int i = 1,j = 10;

12. do{

13. if (i>j) {

14. continue;

15. }

16. j--;

17. } while (++i <6);

18. System.out.println("i = " +i+" and j = "+j);

What is the result?

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 5 and j = 6

E. i = 6 and j = 6

Answer: D


 

QUESTION NO: 69

Which fragment is an example of inappropriate use of assertions?

A. assert (!(map.contains(x)));

map.add(x);

B. if (x > 0) {

} else {

assert (x==0);

}

C. public void aMethod(int x) {

assert (x > 0);

}

D. assert (invariantCondition());

return retval;

E. switch (x) {

case 1: break;

case 2: creak;

default: assert (x == 0);

Answer: C

QUESTION NO: 70

Given:

1. public class X {

2. public X aMethod() { return this;}

3. }

1. public class Y extends X {

2.

3. }

Which two methods can be added to the definition of class Y? (Choose two)

A. public void aMethod() {}

B. private void aMethod() {}

C. public void aMethod(String s) {}

D. private Y aMethod() { return null; }

E. public X aMethod() { return new Y(); }

Answer: C, E


 

QUESTION NO: 71

Given:

1. public class X {

2. public static void main(String [] args) {

3. try {

4. badMethod();

5. System.out.print("A");

6. }

7. catch (Exception ex) {

8. System.out.print("B");

9. }

10. finally {

11. System.out.print("B");

12. }

13. System.out.print("D");

14. }

15. public static void badMethod() {

16. throw new Error();

17. }

18. }

What is the result?

A. ABCD

B. Compilation fails.

C. C is printed before exiting with an error message.

D. BC is printed before exiting with an error message.

E. BCD is printed before exiting with an error message.

Answer: C

JAVA DUMPS 12(SCJP)

QUESTION NO: 60

Given:

1. public class Foo {

2. public void main( String[] args ) {

3. System.out.printIn( "Hello" + args[0] );

4. }

5. }

What is the result if this code is executed with the command line?

java Foo world

A. Hello

B. Hello Foo

C. Hello world

D. Compilation fails.

E. The code does not run.

Answer: E


 

QUESTION NO: 61

Given:

11. public void foo( boolean a, boolean b ){

12. if( a ) {

13. System.out.println( "A" );

14. } else if ( a && b ) {

15. System.out.println( "A&&B" );

16. } else {

17. if ( !b ) {

18. System.out.println( "notB" );

19. } else {

20. System.out.println( "ELSE" );

21. }

22. }

23. }

What is correct?

A. If a is true and b is true then the output is "A&&B".

B. If a is true and b is false then the output is "notB".

C. If a is false and b is true then the output is "ELSE".

D. If a is false and b is false then the output is "ELSE".

Answer: C

QUESTION NO: 62

Which two cause a compiler error? (Choose two)

A. int[] scores = {3, 5, 7};

B. int [][] scores = {2,7,6}, {9,3,45};

C. String cats[] = {"Fluffy", "Spot", "Zeus"};

D. boolean results[] = new boolean [3] {true, false, true};

E. Integer results[] = {new Integer(3), new Integer(5), new

Integer(8)};

F. String[] dogs = new String[]{new String("Fido"),new

String("Spike"), new String("Aiko")};

Answer: B, D


 

QUESTION NO: 63

Given:

11. int i = 0, j = 5;12. tp; for (;;) {

12. i++;

13. for(;;) {

14. if (i> --j) {

15. break tp;

16. break tp;

17. }

18. }

19. System.out.printIn("i=" +i ",j ="+j);

What is the result?

A. i = 1, j = 0

B. i = 1, j = 4

C. i = 3, j = 4

D. i = 3, j = 0

E. Compilation fails.

Answer: E


 

QUESTION NO: 64

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 two changes, independently applied, allow this code to compile? (Choose two)

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: B, E


 

QUESTION NO: 65

Given:

1. public class Test {

2. public static void main(String Args[]) {

3. int i =1, j = 0;

4. switch(i) {

5. case 2: j +=6;

6. case 4: j +=1;

7. default: j +=2;

8. case 0: j +=4;

9. }

10. System.out.printIn("j =" +j);

11. }

12. }

What is the result?

A. 0

B. 2

C. 4

D. 6

E. 9

F. 13

Answer: D


 

QUESTION NO: 66

Given:

1. class A {

2. }

3. class Alpha {

4. private A myA = new A();

5.

6. void dolt( A a ) {

7. a = null;

8. }

9. void tryIt() {

10. dolt( myA );

11. }

12. }

Which two statements are correct? (Choose two)

A. There are no instanced of A that will become eligible for garbage collection.

B. Explicitly setting myA to null marks that instance to be eligible for garbage collection.

C. Any call on tryIt() causes the private instance of A to be marked for garbage

collection.

D. Private instances of A become eligible for garbage collection when instances of Alpha

become eligible for garbage collection.

Answer: B, D

JAVA DUMPS 11(SCJP)

QUESTION NO: 54

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: B


 

QUESTION NO: 55

Given:

11. switch(x) {

12. default:

13. System.out.printIn("Hello");

14. }

Which two are acceptable types for x? (Choose two)

A. byte

B. long

C. char

D. float

E. Short

F. Long

Answer: A, C


 

QUESTION NO: 56

Given:

1. public class X {

2. public static void main(String [] args) {

3. try {

4. badMethod();

5. System.out.print("A");

6. }

7. catch (RuntimeException ex) {

8. System.out.print("B");

9. }

10. catch (Exception ex1) {

11. System.out.print("C");

12. }

13. finally {

14. System.out.print("D");

15. }

16. System.out.print("E");

17. }

18. public static void badMethod() {

19. throw new RuntimeException();

20. }

21. }

What is the result?

A. BD

B. BCD

C. BDE

D. BCDE

E. ABCDE

F. Compilation fails.

Answer: C


 

QUESTION NO: 57

Given:

1. public class Test {

2. public static void main(String[] args) {

3. int x = 0;

4. assert (x > 0) ? "assertion failed" : "assertion passed";

5. System.out.println("Finished");

6. }

7. }

What is the result?

A. finished

B. Compilation fails.

C. An AssertionError is thrown and finished is output.

D. An AssertionError is thrown with the message "assertion failed".

E. An AssertionError is thrown with the message "assertion passed".

Answer: B

QUESTION NO: 58

Given:

1. public class ReturnIt {

2. return Type methodA(byte x, double y) {

3. return (long)x / y * 2;

4. }

5. }

What is the narrowest valid returnType for methodA in line2?

A. int

B. byte

C. long

D. short

E. float

F. double

Answer: F


 

QUESTION NO: 59

Given:

1. public class OuterClass {

2. private double d1 = 1.0;

3. // insert code here

4. }

Which two are valid if inserted at line 3? (Choose two)

A. static class InnerOne {

public double methoda() { return d1; }

}

B. static class InnerOne {

static double methoda() { return d1; }

}

C. private class InnerOne {

public double methoda() { return d1; }

}

D. protected class InnerOne {

static double methoda() { return d1; }

}

E. public abstract class InnerOne {

public abstract double methoda();

}

Answer: C, E

JAVA LINKS

JAVA DUMPS 10(SCJP)

QUESTION NO: 49

Given:

10. public Object m() {

11. Object o = new Float(3.14F);

12. Object [] oa = new Object[1];

13. oa[0] = o;

14. o = null;

15. oa[0] = null;

16. return 0;

17. }

When is the Float object, created in line 11, eligible for garbage collection?

A. Just after line 13.

B. Just after line 14.

C. Just after line 15.

D. Just after line 16 (that is, as the method returns).

Answer: B


 

QUESTION NO: 50

Given:

11. public void test(int x) {

12. int odd = x%2;

13. if (odd) {

14. System.out.println("odd);

15. } else {

16. System.out.println("even");

17. }

18. }

Which statement is true?

A. Compilation fails.

B. "odd" will always be output.

C. "even" will always be output.

D. "odd" will be output for odd values of x, and "even" for even values.

E. "even" will be output for add values of x, and "odd" for even values.

Answer: A


 

QUESTION NO: 51

Which two create an instance of an array? (Choose two)

A. int[] ia = new int[15];

B. float fa = new float[20];

C. char[] ca = "Some String";

D. Object oa = new float[20];

E. int ia[][] = { 4, 5, 6, }, { 1, 2, 3 };

Answer: A, D


 

QUESTION NO: 52

Given:

1. class Super {

2. public int getLenght() { return 4; }

3. }

4.

5. public class Sub extends Super {

6. public long getLenght() { return 5; }

7.

8. public static void main(String[] args) {

9. Super sooper = new Super();

10. Sub sub = new Sub();

11. System.out.println(

12. sooper.getLenght() + "," + sub.getLenght() );

13. }

14. }

What is the output?

A. 4,4

B. 4,5

C. 5,4

D. 5,5

E. Compilation fails.

Answer: E


 

QUESTION NO: 53

Given:

1. public class Test {

2. public static void main(String[] args) {

3. int x = 0;

4. assert (x > 0): "assertion failed";

5. System.out.printIn("finished");

6. }

7. }

What is the result?

A. finished

B. Compilation fails.

C. An AssertionError is thrown.

D. An AssertionError is thrown and finished is output.

Answer: A