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();
}
}
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();
}
}
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
MPignaProTech
2 months, 4 weeks agoMPignaProTech
3 months agodiptimayee
3 months ago7df49fb
10 months agoRavisai_7
1 year, 3 months agoyanoolthecool
1 year, 1 month agococobot
1 year, 3 months agoDriftKing
1 year, 3 months agoakbiyik
2 years, 1 month agoUAK94
2 years, 3 months agoiSnover
2 years, 3 months ago