What is the result when this program is executed?

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);
}
}

What is the result when this program is executed?

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);
}
}

What is the result when this program is executed?

A.
Bob’s Name: Bob

B.
Bob’s Name: Jian

C.
Nothing prints

D.
Bob’s name

Explanation:
After the statement jian = bob; the jian will reference the same object as bob.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Abed Abu Alhalawa

Abed Abu Alhalawa

B.
Bob’s Name: Jian

James

James

Answer is B.

After the statement:

jian = bob;

which sets the Student object reference jian to the Student object reference bob, any changes to the instance variables of jian will be reflected in the bob object.