1z0-808 Practice Test Questions

236 Questions


Given the code fragment?
public class Test {
public static void main(String[] args) {
Test t = new Test();
int[] arr = new int[10];
arr = t.subArray(arr,0,2);
}
// insert code here
}
Which method can be inserted at line // insert code here to enable the code to compile?


A.

public int[] subArray(int[] src, int start, int end) {
return src;
}


B.

public int subArray(int src, int start, int end) {
return src;
}


C.

public int[] subArray(int src, int start, int end) {
return src;
}


D.

public int subArray(int[] src, int start, int end) {
return src;
}





A.
  

public int[] subArray(int[] src, int start, int end) {
return src;
}



Given:

What is the result?


A.

Null


B.

Compilation fails


C.

An exception is thrown at runtime


D.

0





C.
  

An exception is thrown at runtime



Given the code fragment

And given the requirements:
If the value of the qty variable is greater than or equal to 90, discount = 0.5
If the value of the qty variable is between 80 and 90, discount = 0.2
Which two code fragments can be independently placed at line n1 to meet the
requirements?



A.

Option A


B.

Option B


C.

Option C


D.

Option D


E.

Option E





A.
  

Option A



C.
  

Option C



Given:
public class ComputeSum {
public int x;
public int y;
public int sum;
public ComputeSum (int nx, int ny) {
x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();}
public void setY(int ny) { x = ny; updateSum();}
void updateSum() { sum = x + y;}
}
This class needs to protect an invariant on the sum field.
Which three members must have the private access modifier to ensure that this invariant is
maintained?


A.

The x field


B.

The y field


C.

The sum field


D.

The ComputerSum ( ) constructor


E.

The setX ( ) method


F.

The setY ( ) method





C.
  

The sum field



E.
  

The setX ( ) method



F.
  

The setY ( ) method



The sum field and the two methods (setX and SetY) that updates the sum
field.

A method is declared to take three arguments. A program calls this method and passes
only two arguments. What is the results?


A.

Compilation fails.


B.

The third argument is given the value null.


C.

The third argument is given the value void.


D.

The third argument is given the value zero.


E.

The third argument is given the appropriate falsy value for its declared type. F) An
exception occurs when the method attempts to access the third argument.





A.
  

Compilation fails.



Given:
public class Test1 {
static void doubling (Integer ref, int pv) {
ref =20;
pv = 20;
}
public static void main(String[] args) {
Integer iObj = new Integer(10);
int iVar = 10;
doubling(iObj++, iVar++);
System.out.println(iObj+ ", "+iVar);
What is the result?


A.

11, 11


B.

10, 10


C.

21, 11


D.

20, 20


E.

11, 12





A.
  

11, 11



The code doubling(iObj++, iVar++); increases both variables from to 10 to
11.

Given:

And the commands:
Javac Test.java
Java Test 12345
What is the result?


A.

Number us : 12345


B.

A NullPointerException is thrown at runtime


C.

A NumberFormatException is thrown at runtime


D.

AnArrayIndexOutOfBoundException is thrown at runtime.





A.
  

Number us : 12345



Given:

And the commands:
Javac Jump.java
Java Jump crazy elephant is always
What is the result


A.

Lazy lion is jumping


B.

Lion is always jumping


C.

Crazy elephant is jumping


D.

Elephant is always jumping


E.

Compilation fails





B.
  

Lion is always jumping



Given:
Class A { }
Class B { }
Interface X { }
Interface Y { }
Which two definitions of class C are valid?


A.

Class C extends A implements X { }


B.

 Class C implements Y extends B { }


C.

Class C extends A, B { }


D.

Class C implements X, Y extends B { }


E.

Class C extends B implements X, Y { }






A.
  

Class C extends A implements X { }



E.
  

Class C extends B implements X, Y { }




extends is for extending a class.
implements is for implementing an interface.
Java allows for a class to implement many interfaces.

Which of the following will print current time?


A.

System.out.print(new LocalTime()-now0);


B.

System.out.print(new LocalTime());


C.

System.ouLprint(LocalTime.now());


D.

System.ouLprint(LocalTime.today());


E.

None of the above.





C.
  

System.ouLprint(LocalTime.now());



The LocalTime is an interface, so we can't use new keyword with them. So options A and C
are incorrect.
To get current time we can call now method on LocalTime interface. So option C is correct.
Option D is incorrect as there is no method called today as in LocalTime interface
https://docs.oracle.com/javase/tutorial/datetime/iso/datetime.html

Given:

What is the result?


A.

Red 0
Orange 0
Green 3


B.

Red 0
Orange 0
Green 6


C.

Red 0
Orange 1


D.

Green 4


E.

Compilation fails





E.
  

Compilation fails



Given:



A.

Option A


B.

Option B


C.

Option C


D.

Option D





C.
  

Option C




Page 6 out of 20 Pages
Previous