Go Back on 1z0-808 Exam
Available in 1, 3, 6 and 12 Months Free Updates Plans
PDF: $15 $60

Test Engine: $20 $80

PDF + Engine: $25 $99

1z0-808 Practice Test


Page 7 out of 48 Pages

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




Page 7 out of 48 Pages
Previous