1 A constructor Always accepts two arguments Has the same name as the class Has
ID: 3548266 • Letter: 1
Question
1
A constructor
Always accepts two arguments
Has the same name as the class
Has return type of void
Always has an access specifier of private
2
A constructor is a method that
Performs initialization or setup operations
With the name ClassName.constructor
Returns an object of the class
Never receives any arguments
6
For the following code, which statement is not true?
public class Sphere
{
private double radius;
public double x;
private double y;
private double z;
}
z is available to code that is written outside the Sphere class
x is available to code that is written outside the Sphere class
radius is not available to code written outside the Sphere class
radius, x, y, and z are called members of the Sphere class
7
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
private int orderNum;
private double orderAmount;
private double orderDiscount;
public Order(int orderNumber, double orderAmt,
double orderDisc)
{
orderNum = orderNumber;
orderAmount = orderAmt;
orderDiscount = orderDisc;
}
public double finalOrderTotal()
{
return orderAmount - orderAmount *
orderDiscount;
}
}
public class CustomerOrder
{
public static void main(String[] args)
{
Order order;
int orderNumber = 1234;
double orderAmt = 580.00;
double orderDisc = .1;
order = new Order(orderNumber, orderAmt, orderDisc);
double finalAmount = order.finalOrderTotal();
System.out.println("Final order amount = $" +
finalAmount);
}
}
528.00
522.00
580.00
There is no value because the object order has not been created.
8
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
private int orderNum;
private double orderAmount;
private double orderDiscount;
public Order(int orderNumber, double orderAmt,
double orderDisc)
{
orderNum = orderNumber;
orderAmount = orderAmt;
orderDiscount = orderDisc;
}
public int getOrderAmount()
{
return orderAmount;
}
public int getOrderDisc()
{
return orderDisc;
}
}
public class CustomerOrder
{
public static void main(String[] args)
{
int ordNum = 1234;
double ordAmount = 580.00;
double discountPer = .1;
Order order;
double finalAmount = order.getOrderAmount()
Explanation / Answer
Has the same name as the class
Performs initialization or setup operations
x is available to code that is written outside the Sphere class
528
There is no value because the constructor has an error
522
Class name; object name; methods
2
y == 0
0
2
32
A reference to the String "ghi"
in a last-in-first-out fashion
if (top == s.length-1)
throw new RuntimeException("Overflow");
top ++;
s[top] = x;
if (top == -1)
throw new RuntimeException("Empty Stack");
s[top] = null;
top--;
return s[top ];
if (top == -1)
throw new RuntimeException("Empty Stack");
else
return s[top];
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.