Q7
View the exhibit:
public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;
public void display() {
System.out.println("Name: " + name + " Major: " + major);
}
public boolean isFullTime() {
return fulltime;
}
}
Given:
public class TestStudent {
public static void main(String[] args) {
Student bob = new Student();
Student jian = new Student();
bob.name = "Bob";
bob.age = 19;
jian = bob;
jian.name = "Jian";
System.out.println("Bob's Name: " + bob.name);
}
}
A.
Bob’s Name: Bob
Bob’s Name: Bob
B.
Bob’s Name: Jian
Bob’s Name: Jian
C.
Nothing prints
Nothing prints
D.
Bob’s name
Risultato :
Bob's Name: Jian
Dopo l'istruzione jian = bob; il reference jian referenzia lo stesso oggetto come bob.
riferimento : tipi reference
Bob’s name
Risultato :
Bob's Name: Jian
Dopo l'istruzione jian = bob; il reference jian referenzia lo stesso oggetto come bob.
riferimento : tipi reference
Nessun commento:
Posta un commento