Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 25

Given the code fragment:

Which two modifications, when made independently, enable the code to print joe:true: 100.0? (Choose two.)

    Correct Answer: A, D

    The code aims to print 'joe:true: 100.0' when executed. For this output, the `name` field must be 'Joe', the `contract` field must be `true`, and the `salary` field must be 100. Option A correctly sets these values after creating the `Employee` object by directly assigning values to its fields, which is valid. Option D also correctly sets these values but within the constructor, again ensuring that the fields have the required values when the `toString` method is called. Options B and C are incorrect because `this` cannot be used in a static context, and Option E is syntactically incorrect because it attempts to use a constructor that doesn't exist in the given class definition.

Discussion
KolodetsOptions: AC

AC or AD - both correct

carlosworkOptions: AC

Tested. Answer is A and C. Comments: * Option C works even though it has been deprecated since version 9 (1z0-808 is about java 8). ** Option B would only be correct if it is inside the constructor, on line n1. As option B is pointing to line n2, it will throws an error.

carloswork

Here is the code for testing: public class Employee { String name; Boolean contract; double salary; Employee(){ // Line n1 - Option C /* this.name = new String("Joe"); this.contract = new Boolean(true); this.salary = new Double(100); */ } public String toString() { return name + " : " + contract + " : " + salary; } public static void main(String [] args) { Employee e = new Employee(); // Line n2 - Option A /* e.name = "Joe"; e.contract = true; e.salary = 100; */ // Line n2 - Option B /* this.name = "Joe"; this.contract = true; this.salary = 100; */ System.out.print(e); } }

alex_auOptions: AC

Should be A, C. We cannot do B as we cannot use "this" in the static method

7df49fbOptions: AC

AC the last line in main method should be : System.out.print(e.toString();

arjunrawatirissoftwareOptions: AC

Answer - A and C

somrita90Options: AD

A is correct, C is incorrect, boolean is not same as Boolean, so this.contract = new Boolean("True"); is a compilation error for. D can be the another correct option if we are writing true instead of TRUE. Other than this none of these are correct.

KeletsoM23

Why is D not correct?

PedroC123

Because its true and not TRUE.

felipegomeztreufoOption: A

Respuesta correcta es A, recordar que esta en un cotexto estatico por lo que no puede acceder con this ni menos con con la nombre de la variable

Vicky_65Options: AC

A and C

anmoldev2javaOptions: AC

a and c are correct

iSnoverOptions: AC

The correct options are A and C, as all others contain syntax errors. It cannot be the letter B because "this" cannot be instantiated in static methods.

RoxyFoxyOptions: AB

If C, unnecesary boxing to Boolean and Double. If we use "new" we will create new objects.

iSnover

Wrong, you can't put "this" in static methods. The correct one is A and C.

Kolodets

wrong, it is A, C and D