COSC 2436 - Exam 1 Questions and
Answers16
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.printf("Final order amount = $%,.2f\n", finalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object, order, has not been created. - ANSWERS-D) There is no
value because the object, order, has not been created.
Two or more methods in a class may have the same name as long as __________.
A) they have different return types
B) they have different parameter lists
C) they have different return types but the same parameter list
D) You cannot have two methods with the same name. - ANSWERS-B) they have different
parameter lists
, When an object is created, the attributes associated with the object are called __________.
A) instance fields
B) class instances
C) instance methods
D) fixed attributes - ANSWERS-A) instance fields
Methods that operate on an object's fields are called __________.
A) instance variables
B) instance methods
C) public methods
D) private methods - ANSWERS-B) instance methods
The __________ package is automatically imported into all Java programs.
A) java.java
B) java.default
C) java.util
D) java.lang - ANSWERS-D) java.lang
Given the following two-dimensional array declaration, which statement is true?
int[][] numbers = new int[6][9];
A) The numbers array has 54 rows.
Answers16
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.printf("Final order amount = $%,.2f\n", finalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object, order, has not been created. - ANSWERS-D) There is no
value because the object, order, has not been created.
Two or more methods in a class may have the same name as long as __________.
A) they have different return types
B) they have different parameter lists
C) they have different return types but the same parameter list
D) You cannot have two methods with the same name. - ANSWERS-B) they have different
parameter lists
, When an object is created, the attributes associated with the object are called __________.
A) instance fields
B) class instances
C) instance methods
D) fixed attributes - ANSWERS-A) instance fields
Methods that operate on an object's fields are called __________.
A) instance variables
B) instance methods
C) public methods
D) private methods - ANSWERS-B) instance methods
The __________ package is automatically imported into all Java programs.
A) java.java
B) java.default
C) java.util
D) java.lang - ANSWERS-D) java.lang
Given the following two-dimensional array declaration, which statement is true?
int[][] numbers = new int[6][9];
A) The numbers array has 54 rows.