Question: Question 1 Consider the following statements. public class Rectangle { private double length; private double width; public Rectangle() { length = 0; width = 0;
Question 1
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 + " " + + " 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);
| length = 14; width = 10 | ||
| length = 9; width = 5 | ||
| length = 14; width = 5 | ||
| None of these |
1 points
Question 2
ADTs illustrate the principle of ____.
| information hiding | ||
| privacy | ||
| encapsulation | ||
| overloading |
1 points
Question 3
| 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?
| public MysteryClass(){ setData(0, 0.0); } | ||
| public MysteryClass(0, 0.0) { setData(); } | ||
| public MysteryClass(0) { setData(0, 0.0); } | ||
| private MysteryClass(10){ setData(); } |
1 points
Question 4
| 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 classMysteryClass?
| doubleFirst | ||
| MysteryClass | ||
| second | ||
| |
1 points
Question 5
Which of the following class definitions is correct in Java? (i) public class Employee { private String name; private double salary; private int id; public Employee() { name = ""; salary = 0.0; id = 0; } public Employee(String n, double s, int i) { name = n; salary = s; id = i; } public void print() { System.out.println(name + " " + id + " " + salary); } }
(ii)
public class Employee { private String name; private double salary; private int id; public void Employee() { name = ""; salary = 0.0; id = 0; } public void Employee(String n, double s, int i) { name = n; salary = s; id = i; } public void print() { System.out.println(name + " " + id + " " + salary); } }
| Only (i) | ||
| Only (ii) | ||
| Both (i) and (ii) | ||
| Neither is correct |
1 points
Question 6
Class members consist of all of the following EXCEPT ____.
| named constants | ||
| variable declarations | ||
| pre-defined methods | ||
| methods |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
