Exam 8: User-Defined Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

A mutator method of a class changes the values of the data members of the class.

(True/False)
4.8/5
(44)

public class Secret { Private int x; Private static int y; Public static int count; Public int z; Public Secret() { X = 0; Z = 1; } public Secret(int a) { X = a; } public Secret(int a, int b) { X = a; Y = b; } public String toString() { Return ("x = " + x + ", y = " + y + ", Count = " + count); } public static void incrementY() { Y++; } }What might the heading of the copy constructor for the class in the accompanying figure look like?

(Multiple Choice)
5.0/5
(30)

In shallow copying, each reference variable refers to its own object.

(True/False)
4.8/5
(30)

Consider the following class definition.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 + " " + width); } public double area() { Return length * width; } public double perimeter() { Return 2 * length + 2 * width; } }Which of the following statements correctly instantiates the Rectangle object myRectangle? (i) myRectangle = new Rectangle(12.5, 6); (ii) Rectangle myRectangle = new Rectangle(12.5, 6); (iii) class Rectangle myRectangle = new Rectangle(12.5, 6);

(Multiple Choice)
4.8/5
(46)

Every object has access to a reference to itself.

(True/False)
4.7/5
(38)

Consider the following class definition.public class Cylinder { Private double baseRadius; Private double height; public Cylinder () { BaseRadius = 0; Height = 0; } public Cylinder (double l, double h) { BaseRadius = l; Height = h; } public void set(double r, double h) { BaseRadius = r; Height = h; } public String toString() { Return (baseRadius + " " + height); } public double SurfaceArea() { Return 2 * 3.14 * baseRadius * height; } public double volume() { Return 3.14 * baseRadius * baseRadius * height; } }Suppose that you have the following declaration. Cylinder cyl = new Cylinder(1.5, 10);Which of the following sets of statements are valid in Java? (i) Cyl.surfaceArea(); Cyl.volume(); Cyl.print(); (ii) Print(cyl.surfaceArea); Print(cyl.volume());

(Multiple Choice)
4.9/5
(44)

A constructor has no type and is therefore a void method.

(True/False)
4.9/5
(37)

MysteryClass -first: int -second: double; +MysteryClass() +MysteryClass(int) +MysteryClass(double); +MysteryClass(int, double) +setData(int, double): void +getFirst(): int +getSecond(): double +doubleFirst(): int +squareSecond(): double +print(): void +equals(MysteryClass): boolean +makeCopy(MysteryClass): void +getCopy():MysteryClass According to the UML class diagram in the accompanying figure, which method is public and doesn't return anything?

(Multiple Choice)
4.9/5
(44)

Modifiers are used to alter the behavior of the class.

(True/False)
4.8/5
(32)

public class Secret { Private int x; Private static int y; Public static int count; Public int z; Public Secret() { X = 0; Z = 1; } public Secret(int a) { X = a; } public Secret(int a, int b) { X = a; Y = b; } public String toString() { Return ("x = " + x + ", y = " + y + ", Count = " + count); } public static void incrementY() { Y++; } }Based on the class in the accompanying figure, which of the following statements is illegal?

(Multiple Choice)
4.9/5
(44)

The method finalize automatically executes when the class object goes out of scope.

(True/False)
4.8/5
(39)

In Java, the reference this is used to refer to only the methods, not the instance variables of a class.

(True/False)
4.8/5
(38)

ADTs illustrate the principle of ____.

(Multiple Choice)
5.0/5
(32)

What is the default definition of the method toString?

(Multiple Choice)
4.9/5
(32)

The built-in operation that is valid for classes is the dot operator.

(True/False)
4.8/5
(48)

When does the method finalize execute?

(Multiple Choice)
4.9/5
(35)

An accessor method of a class first accesses the values of the data members of the class and then changes the values of the data members.

(True/False)
4.8/5
(32)

public class Secret { Private int x; Private static int y; Public static int count; Public int z; Public Secret() { X = 0; Z = 1; } public Secret(int a) { X = a; } public Secret(int a, int b) { X = a; Y = b; } public String toString() { Return ("x = " + x + ", y = " + y + ", Count = " + count); } public static void incrementY() { Y++; } }What does the default constructor do in the class definition in the accompanying figure?

(Multiple Choice)
4.9/5
(32)

In deep copying, each reference variable refers to its own object.

(True/False)
4.8/5
(44)

When no object of the class type is instantiated, static data members of the class fail to exist.

(True/False)
4.9/5
(39)
Showing 21 - 40 of 50
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)