1z0-808 Practice Test Questions

236 Questions


Given the following main method:

What is the result?


A.

5 4 3 2 1 0


B.

5 4 3 2 1


C.

4 2 1


D.

5


E.

Nothing is printed





D.
  

5



Loop will run only once and after that num == 0 will break it
After first cycle of the loop.

Given the code fragment:
class Student {
int rollnumber;
String name;
List cources = new ArrayList();
// insert code here
public String toString() {
return rollnumber + " : " + name + " : " + cources;
}
}
And,
public class Test {
public static void main(String[] args) {
List cs = newArrayList();
cs.add("Java");
cs.add("C");
Student s = new Student(123,"Fred", cs);
System.out.println(s);
}
}
Which code fragment, when inserted at line // insert code here, enables class Test to print
123 : Fred : [Java, C]?


A.

private Student(int i, String name, List cs) {
/* initialization code goes here */
}


B.

public void Student(int i, String name, List cs) {
/* initialization code goes here */
}


C.

Student(int i, String name, List cs) {
/* initialization code goes here */
}


D.

Student(int i, String name, ArrayList cs) {
/* initialization code goes here */
}





C.
  

Student(int i, String name, List cs) {
/* initialization code goes here */
}



Incorrect:
Not A: Student has private access line: Student s = new Student(123,"Fred", cs);
Not D: Cannot be applied to given types. Line: Student s = new Student(123,"Fred", cs);


A.

Option A


B.

Option B


C.

Option C


D.

Option D





D.
  

Option D




A.

Option A


B.

Option B


C.

Option C


D.

Option D





B.
  

Option B



Given:


What is the result?


A.

Compilation fails


B.

The code compiles, but does not execute.


C.

Paildrome


D.

Wow


E.

Mom





B.
  

The code compiles, but does not execute.



Given:

Which constructor initializes the variable x3?


A.

Only the default constructor of class X


B.

Only the no-argument constructor of class Y


C.

Only the no-argument constructor of class Z


D.

Only the default constructor of object class





C.
  

Only the no-argument constructor of class Z



Given the following class:


And given the following main method, located in another class:
Which three lines, when inserted independently at line n1, cause the program to print a o
balance?


A.

this.amount = 0;


B.

amount = 0;


C.

acct (0) ;


D.

acct.amount = 0;


E.

acct. getAmount () = 0;


F.

acct.changeAmount(0);


G.

acct.changeAmount(-acct.amount);


H.

acct.changeAmount(-acct.getAmount());





D.
  

acct.amount = 0;



G.
  

acct.changeAmount(-acct.amount);



H.
  

acct.changeAmount(-acct.getAmount());



Given:

What is the result?


A.

C B A


B.

C


C.

A B C


D.

Compilation fails at line n1 and line n2





C.
  

A B C



Given:

What is the result?


A.

myStr: 9009, myNum: 9009


B.

myStr: 7007, myNum: 7007


C.

myStr: 7007, myNum: 9009


D.

Compilation fails





C.
  

myStr: 7007, myNum: 9009



Given:
import java.util.*;
public class Ref {
public static void main(String[] args) {
StringBuilder s1 = new StringBuilder("Hello Java!");
String s2 = s1.toString();
List<String> lst = new ArrayList<String>();
lst.add(s2);
System.out.println(s1.getClass());
System.out.println(s2.getClass());
System.out.println(lst.getClass());
}
}
What is the result?


A.

class java.lang.String
class java.lang.String
class java.util.ArrayList


B.

class java.lang.Object
class java.lang. Object
class java.util.Collection


C.

class java.lang.StringBuilder
class java.lang.String
class java.util.ArrayList


D.

class java.lang.StringBuilder
class java.lang.String
class java.util.List





C.
  

class java.lang.StringBuilder
class java.lang.String
class java.util.ArrayList



class java.lang.StringBuilder
class java.lang.String
class java.util.ArrayList

Given the code fragment:

What is the result?


A.

 true true


B.

True false


C.

false false


D.

false true


L.

       





C.
  

false false



Given:
public class TestField {
int x;
int y;
public void doStuff(int x, int y) {
this.x = x;
y =this.y;
}
public void display() {
System.out.print(x + " " + y + " : ");
}
public static void main(String[] args) {
TestField m1 = new TestField();
m1.x = 100;
m1.y = 200;
TestField m2 = new TestField();
m2.doStuff(m1.x, m1.y);
m1.display();
m2.display();
}
}
What is the result?


A.

100 200 : 100 200


B.

100 0 : 100 0 :


C.

 100 200 : 100 0 :


D.

100 0 : 100 20





C.
  

 100 200 : 100 0 :




Page 2 out of 20 Pages
Previous