Oracle
1Z0-809 · Question #183
Given the code fragment: public class Person { String name; int age = 25; public Person(String name) { this(); //line n1 setName(name); } public Person(String name, int age) { Person(name); //line…
The correct answer is A. Compilation fails at both line n1 and line n2. You've hit your session limit · resets 10:20pm (America/New_York)
Question
Given the code fragment:
public class Person {
String name;
int age = 25;
public Person(String name) {
this(); //line n1
setName(name);
}
public Person(String name, int age) {
Person(name); //line n2
setAge(age);
}
//setter and getter methods go here
public String show() {
return name + " " + age;
}
public static void main(String[] args) {
Person p1 = new Person("Jesse");
Person p2 = new Person("Walter", 52);
System.out.println(p1.show());
System.out.println(p2.show());
}
}
What is the result?
Options
- ACompilation fails at both line n1 and line n2.
- BCompilation fails only at line n1.
- CJesse 25
- DCompilation fails only at line n2.
How the community answered
(45 responses)- A82% (37)
- B2% (1)
- C7% (3)
- D9% (4)
Explanation
You've hit your session limit · resets 10:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.