Given:
Given the code fragment:
Which two sets of actions, independently, enable the code fragment to print Fit?
Given:
Given the code fragment:
Which two sets of actions, independently, enable the code fragment to print Fit?
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'.
A and C are both correct.
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(); } }
Tested. Answer A and C are correct.
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(); } }
answer : A & C
A & D are correct
nope, compiler wont see what 'shirt' is.
A and C are correct