What is the result when this program is executed?

View the exhibit:
<code>
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;
}
</code>
Given:
<code>
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);
}
</code>
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 5

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


Carlos

Carlos

this exam don´t work I lost the exam

Paul

Paul

Where is the right exam?

sully

sully

It’s only sample questions not real exam questions

sully

sully

You need to include some } if this were
a program wouldn’t compile.
1 } missing from 1st and 2nd class

Hans

Hans

jian and bob reference the same object, so when you change jian’s name To Jian, you changes bob name to Jian.
B.