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

Given:

Given the code fragment:

Which two sets of actions, independently, enable the code fragment to print Fit?

    Correct Answer: A, C

    To enable the code fragment to print 'Fit', it is necessary to import the Shirt class from the clothing package or to use a static import for the getColor method. The correct answers are: (1) At line n1, insert 'import clothing.Shirt;' and at line n2, insert 'String color = Shirt.getColor();', and (2) At line n1, insert 'import static clothing.Shirt.getColor;' and at line n2, insert 'String color = getColor();'. Both these sets of changes will allow the code to compile successfully and print 'Fit'.

Discussion
akbiyikOption: A

A and C are both correct.

UAK94Option: A

A and C are both correct. package clothing.pants; //import clothing.Shirt; import static clothing.Shirt.getColor; public class Jeans { public void matchShirt() { // String color = Shirt.getColor(); String color = getColor(); if (color.equals("Green")) { System.out.print("Fit"); } } public static void main(String[] args) { Jeans trouser = new Jeans(); trouser.matchShirt(); } }

Drift_KingOption: A

Tested. Answer A and C are correct.

iSnoverOption: A

The correct answer is the letter A. Even though it is in a subpackage, it is necessary to import the class from the parent package even though it is public to have access to the method, so we have to put the "import clothing.Shirt;" on line n1. In line 2 just instantiate the variable "color" that is inside the if in the next line that will print "Fit". I tested the code if you want: * Shirt.java: --------------------------------------------------------------------------- package clothing; public class Shirt { public static String getColor() { return "Green"; } } --------------------------------------------------------------------------- * Jeans.java: package clothing.pants; import clothing.Shirt; public class Jeans { public void matchShirt () { String color = Shirt.getColor(); if(color.equals("Green")) { System.out.print("Fit"); } } public static void main(String[] args) { Jeans trouser = new Jeans(); trouser.matchShirt(); } }

7df49fbOption: A

answer : A & C

Ravisai_7Option: A

A & D are correct

yanoolthecool

nope, compiler wont see what 'shirt' is.

cocobotOption: A

A and C are correct