exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 34 discussion

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

Given:
public class Test<T> {
private T t;
public T get () {
return t;
}
public void set (T t) {
this.t = t;
}
public static void main (String args [ ] ) {
Test<String> type = new Test<>();
Test type 1 = new Test (); //line n1
type.set("Java");
type1.set(100); //line n2
System.out.print(type.get() + " " + type1.get());
}
}
What is the result?

  • A. Java 100
  • B. java.lang.string@<hashcode>java.lang.Integer@<hashcode>
  • C. A compilation error occurs. To rectify it, replace line n1 with: Test<Integer> type1 = new Test<>();
  • D. A compilation error occurs. To rectify it, replace line n2 with: type1.set (Integer(100));
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
jduarte
Highly Voted 3 years, 6 months ago
Answer A. tested
upvoted 8 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
A is the correct answer public class Test<T> { private T t; public T get() { return t; } public void set(T t) { this.t = t; } public static void main(String args[]) { Test<String> type = new Test<>(); Test type1 = new Test<>(); // corrected line n1 type.set("Java"); type1.set(100); // corrected line n2 System.out.print(type.get() + " " + type1.get()); } }
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: A
A is correct.
upvoted 1 times
...
DangNHH
1 year, 4 months ago
Answer A At line n1, Generic type data was not defined. Thus, line n2 is valid. The generic type will be set as an integer. Test type 1 = new Test (); //line n1 type1.set(100); //line n2 Besides, the variable name "type 1" should be removed space.
upvoted 2 times
...
r1muka5
1 year, 5 months ago
Correct answer is C, the space should be removed.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is A.
upvoted 1 times
...
YasinGaber
2 years, 5 months ago
I think answer should be C, because at line #1 there is a space in (type 1), it has to be either (type1) or (type<Integer>1): public class TestCode<T> { private T t; public T get () { return t; } public void set (T t) { this.t = t; } public static void main(String[] args) { TestCode<String> type = new TestCode<>(); TestCode<Integer> type1 = new TestCode (); //line n1 type.set("Java"); type1.set(100); //line n2 System.out.print(type.get() + " " + type1.get()); } }
upvoted 1 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