Exam 8: User-Defined Classes

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

Not every user-defined class can override the default definition of the method toString because it is provided by Java.

Free
(True/False)
4.8/5
(35)
Correct Answer:
Verified

False

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; } public void makeCopy(Rectangle otherRect) { Length = otherRect.length; Width = otherRect.width } }Rectangle tempRect = new Rectangle(14, 10); Rectangle newRect = new Rectangle(9, 5);What are the values of the instance variables of newRect after the following statement execute?newRect.makeCopy(tempRect);

Free
(Multiple Choice)
4.8/5
(40)
Correct Answer:
Verified

A

Which of the following is used to allocate memory for the instance variables of an object of a class?

Free
(Multiple Choice)
4.7/5
(38)
Correct Answer:
Verified

C

Class members consist of all of the following EXCEPT ____.

(Multiple Choice)
4.9/5
(32)

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 Which of the following would be a default constructor for the class MysteryClass shown in the accompanying figure?

(Multiple Choice)
4.7/5
(26)

Which of the following words indicates an object's reference to itself?

(Multiple Choice)
4.7/5
(45)

How many finalizers can a class have?

(Multiple Choice)
4.7/5
(45)

Classes that are defined within other classes are called inside classes.

(True/False)
4.9/5
(32)

Constructors are called like any other method.

(True/False)
4.8/5
(42)

Given the declaration public class MyClass { private int x; public void print() { System.out.println("x = " + x); } private void setX(int y) { x = y; } } MyClass myObject = new MyClass();The following statement is legal.myObject.print();

(True/False)
4.8/5
(31)

If a member of a class is a private method, you can access it outside the class.

(True/False)
4.8/5
(40)

The methods of a class must be public.

(True/False)
4.8/5
(43)

The components of a class are called fields.

(True/False)
4.8/5
(39)

Which of the following is a constructor without parameters?

(Multiple Choice)
4.9/5
(40)

The default constructor executes when an object is instantiated and initialized using an existing object.

(True/False)
4.8/5
(34)

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 of the following is a private member of the class MysteryClass?

(Multiple Choice)
4.8/5
(32)

A class and its members can be described graphically using Unified Modeling Language (UML) notation.

(True/False)
4.7/5
(41)

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++; } }How many constructors are present in the class definition in the accompanying figure?

(Multiple Choice)
4.7/5
(29)

What is the main use of inner classes?

(Multiple Choice)
4.9/5
(31)

Constructors have the same name as the ____.

(Multiple Choice)
4.8/5
(33)
Showing 1 - 20 of 50
close modal

Filters

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