What is the result?

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 ();
bob.name = “Bob”;
bob.age = 18;
bob.year = 1982;
}
</code>
What is the result?

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 ();
bob.name = "Bob";
bob.age = 18;
bob.year = 1982;
}

What is the result?

A.
year is set to 1982.

B.
bob.year is set to 1982

C.
A runtime error is generated.

D.
A compile time error is generated.



Leave a Reply 2

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


sully

sully

how comes it doesn’t compile is it because when name is initialized doesn’t have
default value or is it something else

Rolandas

Rolandas

E correct. Class Student does not has member year 🙂