Need help on homework in java! thank you 1. When defining a constructor, what do
ID: 3668482 • Letter: N
Question
Need help on homework in java! thank you
1. When defining a constructor, what do you specify for the type of the value returned?
Select one:
a. a primitive
b. an object
c. a primitive or an object
d. void
e. none of the above
2.
Each object has its own copy of every instance data variable.
Select one:
True
False
3.
Instance data variables can be primitive types or objects.
Select one:
True
False
4.
Local data declared inside of a method is saved in memory as long as the object that invokes the method is saved in memory.
Select one:
True
False
5
For the next eight questions, use the following class:
public class Student {
private String name;
private String major;
private double gpa;
private int hours;
public Student(String newName, String newMajor, double newGPA, int newHours) {
name = newName;
major = newMajor;
gpa = newGPA;
hours = newHours;
}
public String toString() {
String s = name + " " + major + " " + gpa + " " + hours;
return s;
}}
A.
Consider the code fragments below:
Student s = new Student(...);
int n = 4;
What is stored in memory at the location of the variable s?
Select one:
i. a memory location to somewhere else in memory
ii. the information that describes a student
iii. none of the above
B.
Consider the code fragments below:
Student s = new Student(...);
int n = 4;
What is stored in memory at the location of the variable n?
Select one:
i. a memory location to somewhere else in memory
ii. the value 4
iii. none of the above
Explanation / Answer
1.e
Explanation-->A constructor can not return a value because a constructor implicitly returns the reference ID of an object, and since a constructor is also a method and a method can't return more than one values. So we say explicitely constructor does not have a return value.
2.True
Explanation-->instance variables belong to an object, since an object is an instance of a class. Every object has it’s own copy of the instance variables.
3.True
Explanation-->The instance data are the entities that make up the class and may be any type available whether primitive or object, and may be public or private. By using objects as instance data, it permits the class to be built upon other classes. This relationship where a class has instance data that are other classes is known as a has-a relationship.
4.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.