1z0-808 Practice Test Questions

236 Questions


Given the following two classes:

How should you write methods in the ElectricAccount class at line n1 so that the member
variable bill is always equal to the value of the member variable kwh multiplied by the
member variable rate?
Any amount of electricity used by a customer (represented by an instance of the customer
class) must contribute to the customer's bill (represented by the member variable bill)
through the method useElectricity method. An instance of the customer class should never
be able to tamper with or decrease the value of the member variable bill.



A.

Option A


B.

Option B


C.

Option C


D.

Option D





B.
  

Option B




A.

a, e
i, o


B.

a, e
o, o


C.

e, e
I, o


D.

e, e
o, o





B.
  

a, e
o, o



Given the code fragment:
What is the result?


A.

May 04, 2014T00:00:00.000


B.

2014-05-04T00:00: 00. 000


C.

5/4/14T00:00:00.000


D.

An exception is thrown at runtime.





D.
  

An exception is thrown at runtime.



java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay

Given:


What is the result?


A.

True false


B.

True null


C.

Compilation fails


D.

A NullPointerException is thrown at runtime





A.
  

True false



Given:

What is the result?


A.

The sum is 2


B.

The sum is 14


C.

 The sum is 15


D.

The loop executes infinite times


E.

Compilation fails





E.
  

Compilation fails



Which two are benefits of polymorphism?


A.

Faster code at runtime


B.

More efficient code at runtime


C.

More dynamic code at runtime


D.

 More flexible and reusable code


E.

Code that is protected from extension by other classes





C.
  

More dynamic code at runtime



D.
  

 More flexible and reusable code



Which three statements are true about the structure of a Java class?

 


A.

class can have only one private constructor.


B.

A method can have the same name as a field.


C.

A class can have overloaded static methods.


D.

A public class must have a main method.


E.

The methods are mandatory components of a class.


F.

The fields need not be initialized before use.





A.
  

class can have only one private constructor.



B.
  

A method can have the same name as a field.



C.
  

A class can have overloaded static methods.



A: Private constructors prevent a class from being explicitly instantiated by its
callers.
If the programmer does not provide a constructor for a class, then the system will always
provide a default, public no-argument constructor. To disable this default constructor,
simply add a private no-argument constructor to the class. This private constructor may be
empty.
B: The following works fine:
int cake() {
int cake=0;
return (1);
}
C: We can overload static method in Java. In terms of method overloading static method
are just like normal methods and in order to overload static method you need to provide
another static method with same name but different method signature.
Incorrect:
Not D: Only a public class in an application need to have a main method.
Not E:
Example:
class A
{
public string something;
public int a;
}
Q: What do you call classes without methods?
Most of the time: An anti pattern
Why? Because it faciliates procedural programming with "Operator" classes and data
structures. You separate data and behaviour which isn't exactly good OOP.
Often times: A DTO (Data Transfer Object)
Read only datastructures meant to exchange data, derived from a business/domain object.
Sometimes: Just data structure.
Well sometimes, you just gotta have those structures to hold data that is just plain and
simple and has no operations on it.
Not F: Fields need to be initialtized. If not the code will not compile.
Example:
Uncompilable source code - variable x might not have been initialized

Which of the following data types will allow the following code snippet to compile?


A.

long


B.

double


C.

int


D.

float


E.

byte





B.
  

double



D.
  

float



Option B and D are the correct answer.
Since the variables I and j are floats, resultant will be float type too. So we have to use float
or primitive type which can hold float, such a primitive type is double, it has wider range
and also can hold floating point numbers, hence we can use double or float for the blank.
As explained above options B and D are correct.
long and int can't be used with floating point numbers so option A is incorrect.
Option E is incorrect as it have smaller range and also can't be used with floating point
numbers.hnpsy/docs.oracle.com/javase/tutorial/java/javaOO/variables.html

Which of the following can fill in the blank in this code to make it compile?



A.

abstract


B.

public


C.

default


D.

It will not compile with any as interfaces cannot have non abstract methods.


E.

It will compile without filling the blank.





C.
  

default



From Java SE 8, we can use static and/or default methods in interfaces, but they should be
non abstract methods. SO in this case using default in blank is completely legal. Hence
option C is correct.
Option A is incorrect as given method is not abstract, so can't use abstract there.
Options B and E are incorrect as we can't have non abstract method interface if they are
not default or static.
https;//docs.oraclexom/javase/tutorial/java/Iandl/defaultmethods.html

Given:

What is the result?


A.

10 : 22 : 20


B.

10 : 22 : 22


C.

10 : 22 : 6


D.

10 : 30 : 6





B.
  

10 : 22 : 22



Given:

What is the result?


A.

3 4 5 6


B.

3 4 3 6


C.

5 4 5 6


D.

3 6 4 6





C.
  

5 4 5 6



Given the code fragment:
public static void main(String[] args) {
int iArray[] = {65, 68, 69};
iArray[2] = iArray[0];
iArray[0] = iArray[1];
iArray[1] = iArray[2];
for (int element : iArray) {
System.out.print(element + " ");
}


A.

68, 65, 69


B.

68, 65, 65


C.

65, 68, 65


D.

65, 68, 69


E.

Compilation fails





B.
  

68, 65, 65




Page 3 out of 20 Pages
Previous