OD
(Choose 1 answer)
public class Example {
Given the following. What is the result?
public static void main(String[] args) {
Person p1 = new Person("Hung", 20);Person p2 = new Person("Ha", 22);
A. Compilation fails
Person p3 = (new Example()).change(p2, change(p2, " Nam");
B. 1 Nam 22
System.out.println(p3.getCode() + "" + p3.name + + p3.age);}
public Person change (Person p, String name) {
C. ClassCastException is thrown at runtime
Person p1 = p;
p1.name=name;
D. 2 Nam 22
return p1;
}
}
class Person {
private int code;
String name;
int age;
public Person(String name, int age) {
this.code++;this.name = name;
this.age = age;
} public int getCode() {return code;}
}
Exit 40