How can we help?

You can also find more resources in our Help Center.

9 terms

Quiz 12

STUDY
PLAY
The reference to an object that is passed to any object's nonstatic class method is called the ____.

1. this reference
2. magic number
3. literal constant
4. reference
1. This
Which of the following class definitions is correct in Java?
(i)
public class Student
{
private String name;
private double gpa;
private int id;

public void Student()
{
name = "";
gpa = 0;
id = 0;
}

public void Student(String s, double g, int i)
{
set(s, g, i);
}

public void set(String s, double g, int i)
{
name = s;
gpa = g;
id = i;
}

public void print()
{
System.out.println(name + " " + id + " " + gpa);
}
}

(ii)
public class Student
{
private String name;
private double gpa;
private int id;

public Student()
{
name = "";
gpa = 0;
id = 0;
}

public Student(String s, double g, int i)
{
set(s, g, i);
}

public void set(String s, double g, int i)
{
name = s;
gpa = g;
id = i;
}

public void print()
{
System.out.println(name + " " + id + " " + gpa);
}
}

1. Both (i) and (ii)
2. None of these
3. Only (ii)
4. Only (i)
3. Only ii
If a class's only constructor requires an argument, you must provide an argument for every ____ of the class that you create.

1. object
2. type
3. parameter
4. method
1. Object
The arguments in a method call are often referred to as ____.

1. concept parameters
2. constants
3. actual parameters
4. argument lists
3. Actual parameters
Which of the following is used to allocate memory for the instance variables of an object of a class?

1. the reserved word public
2. the operator new
3. the operator +
4. the reserved word static
2. The operator new
Methods that require you to use an object to call them are called ____ methods.

1. accessor
2. instance
3. internal
4. static
2. Instance
An object is a(n) ____ of a class.

1. instance
2. method
3. field
4. constant
1. Instance
Consider the following statements.

public class Rectangle
{
private double length;
private double width;

public Rectangle()
{
length = 0;
width = 0;
}

public Rectangle(double l, double w)
{
length = l;
width = w;
}

public void set(double l, double w)
{
length = l;
width = w;
}

public void print()
{
System.out.println("Length = " + length
+ "; Width = " + width + "\n" +
+ " Area = " + area()
+ "; Perimeter = " + perimeter());
}

public double area()
{
return length * width;
}

public void perimeter()
{
return 2 length + 2 width;
}
}

What is the output of the following statements?
3. Length = 14.0; Width = 10.0
Area = 140.0; Perimeter = 48.0
public class Illustrate
{
private int x;
private int y;

public Illustrate()
{
x = 1;
y = 2;
}

public Illustrate(int a)
{
x = a;
}

public void print()
{
System.out.println("x = " + x + ", y = " + y);
}

public void incrementY()
{
y++;
}
}
What does the default constructor do in the class definition above?

1. Sets the value of x to 0
2. There is no default constructor.
3. Sets the value of x to 1
4. Sets the value of x to a
3. Sets the value of x to 1.