exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 120 discussion

Actual exam question from Oracle's 1z0-808
Question #: 120
Topic #: 1
[All 1z0-808 Questions]

Given:

Given the code fragment:

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

  • A. At line n1 insert: import clothing.Shirt; At line n2 insert: String color = Shirt.getColor();
  • B. At line n1 insert: import clothing; At line n2 insert: String color = Shirt.getColor();
  • C. At line n1 insert: import static clothing.Shirt.getColor; At line n2 insert: String color = getColor();
  • D. At line n1 no changes required. At line n2 insert: String color = Shirt.getColor();
  • E. At line n1 insert: import Shirt; At line n2 insert: String color = Shirt.getColor();
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
2 months, 4 weeks ago
A/C are both correct
upvoted 1 times
...
MPignaProTech
3 months ago
Selected Answer: D
no need to import from the same package. D
upvoted 1 times
...
diptimayee
3 months ago
A and C are correct.C is using static import feature
upvoted 1 times
...
7df49fb
10 months ago
answer : A & C
upvoted 1 times
...
Ravisai_7
1 year, 3 months ago
A & D are correct
upvoted 1 times
yanoolthecool
1 year, 1 month ago
nope, compiler wont see what 'shirt' is.
upvoted 1 times
...
...
cocobot
1 year, 3 months ago
A and C are correct
upvoted 1 times
...
DriftKing
1 year, 3 months ago
Tested. Answer A and C are correct.
upvoted 2 times
...
akbiyik
2 years, 1 month ago
A and C are both correct.
upvoted 3 times
...
UAK94
2 years, 3 months ago
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(); } }
upvoted 3 times
...
iSnover
2 years, 3 months ago
Selected Answer: 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(); } }
upvoted 2 times
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago