Given the following code, what will be the value of finalAmount when it is displ
ID: 3574757 • Letter: G
Question
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() —
order.getOrderAmount() * order.getOrderDisc();
System.out.println("Final order amount = $" +
finalAmount);
}
}
Explanation / Answer
Answer: There is no value because the object order has not been created.
There is a compilation error because Order order; has not been created.
We just decalred that Order object but not initialized. we need to initilaize that object first then only we can access object properties.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.