Question
Java: Answer with explaination. Thanks QUESTION 31 MysteryClass -first: int -second: double; +MysteryClass() +MysteryClass(int) +MysteryClass(double); +MysteryClass(int, double) +setData(int, double): void +getFirst(): int +getSecond(): double +doubleFirst():
Java: Answer with explaination. Thanks
QUESTION 31
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?
a. | private MysteryClass(10){ setData(); } | |
b. | public MysteryClass(0, 0.0) { setData(); } | |
c. | public MysteryClass(){ setData(0, 0.0); } | |
d. | public MysteryClass(0) { setData(0, 0.0); } |
32. 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);
a. | Only (i) | |
b. | Only (ii) | |
c. | Only (iii) | |
d. | Both (ii) and (iii) |
QUESTION 36
What is the default definition of the method toString?
a. | It creates a string that is the name of the program. | |
b. | It creates a string that is the name of the package, followed by the name of the class, followed by the hash of the object. | |
c. | There is no default definition; you must define the method yourself. | |
d. | It creates a string that is the name of the objects class, followed by the hash code of the object. |
QUESTION 39
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?
a. | Secret.count++; | |
b. | Secret.incrementY(); | |
c. | Secret secret = new Secret(4); | |
d. | Secret.z++; |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started