Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 18

Given:

Which two lines of code when inserted in line 1 correctly modifies instance variables? (Choose two.)

    Correct Answer: C, E

    To correctly modify the instance variables with the given parameters, we should use methods and direct assignments appropriately. The line `setGCount(g);` correctly assigns the value of `g` to the instance variable `gCount` using the setter method, and the line `aCount = a;` correctly assigns the parameter `a` to the instance variable `aCount`. Therefore, the correct lines to be inserted at line 1 are `setGCount(g);` and `aCount = a;`.

Discussion
SuperDabichoOptions: CE

A is not correct because it has "retutn". B is not correct because setC returns an int and it doesn't set anything. D is not correct because both refer to the parameter variable, not the class variable.

Ankit1010

A, C, E are the correct answers.

RoxyFoxyOptions: AE

public class DNASynth { int aCount; int tCount; int cCount; int gCount; DNASynth(int a, int tCount, int c, int g){ cCount = setCCount(c); aCount = a; setGCount(g); } int setCCount(int c){ return c; } void setGCount(int gCount){ this.gCount = gCount; } public static void main(String[] args) { DNASynth pop = new DNASynth(1,2,3,4); System.out.println(pop.aCount+" "+pop.cCount+" "+pop.gCount); // 1 3 4 } } The correct answers: A C E

Mukes877Options: AC

ACE are correct

RP384Options: AC

A, C and E are valid answers

SampsOptions: AE

ACE is correct

StavokOptions: CE

A is incorrect because -The method setCCount(int) is undefined for the type B is incorrect because - The left-hand side of an assignment must be a variable D is incorrect because - The assignment to variable tCount has no effect... C& E Are correct answers

d7bb0b2

A. cCount = setCCount(c); C. setGCount(g); E. aCount = a; have 3 correct answers

[Removed]Options: CE

Correct answer should be A, C and E. If you would take into account that the return-statement in method setCCount is misspelled, then the code would not compile and that answer is not an option. If you can only choose two then it should be C and E but in that case the code would not work at all.

UcefSoftOptions: CE

C. setGCount(g); also

UcefSoftOptions: CE

SetGcount also