I need those question\'s answear. QUESTION 1 You have created a Fruit class and
ID: 3682671 • Letter: I
Question
I need those question's answear.
QUESTION 1
You have created a Fruit class and a ShoppingCart class. Which of the following methods will correctly add a Fruit object to an array list named fruits in the ShoppingCart class?
public void add(Fruit aFruit)
{
fruits.add(new Fruit(aFruit));
}
public void add(Fruit aFruit)
{
fruits.add(aFruit);
}
public void add(Fruit aFruit)
{
fruits.addItem(new Fruit(aFruit));
}
public void add(Fruit aFruit)
{
fruits.addItem(aFruit);
}
2 points
QUESTION 2
Which of the following statements about encapsulation is correct?
Encapsulation enables changes to the public interface without affecting users of the class.
Encapsulation prohibits changes to the implementation details to ensure that users of the class will not be affected.
Encapsulation enables changes to the implementation details without affecting users of the class.
Encapsulation provides an easier means of transporting class information.
2 points
QUESTION 3
Which of the following statements about constructors is correct?
A class can have only one constructor.
A constructor should always return a value.
A class must have at least one constructor supplied by the programmer.
A constructor must have the same name as the class.
2 points
QUESTION 4
Which of the following statements about constructors is NOT correct?
A constructor must have the same name as the class name.
A call to a constructor must always have construction parameters.
A constructor initializes the instance variables of an object.
A class can have more than one constructor.
2 points
QUESTION 5
Which of the following statements about testing a class is correct?
A unit test verifies that only one method within a class works correctly.
A unit test verifies that a class works correctly when it is in a complete program.
A unit test verifies that a class works correctly in isolation, outside a complete program.
A unit test does not need to know what results are expected.
2 points
QUESTION 6
Which of the following statements is true regarding classes?
Each object of a class has a separate copy of each instance variable.
All objects created from a class share a single set of instance variables.
Private instance variables can be accessed by any user of the object.
Public instance variables can be accessed only by the object itself.
2 points
QUESTION 7
Consider the following code snippet:
Coin coin1 = null;
System.out.println("Value of coin = " + coin1.getValue());
What is wrong with this code?
coin1 does not refer to an object and will result in an error at run time.
You cannot concatenate a numeric value with a string value.
The value variable in coin1 has not been set, and will print as 0.
There is nothing wrong with this code.
2 points
QUESTION 8
Which of the following is NOT part of the declaration of an instance variable?
the return type
a modifier specifying the level of access
the data type
the name
2 points
QUESTION 9
You have created an Employee class. You wish to have a unique, sequential employee number assigned to each new Employee object that is created. Which of the following declarations, if added to the Employee class, would allow you to determine which number was last assigned when you are creating a new Employee object?
private static int lastAssignedEmpNum = 500;
public int lastAssignedEmpNum = 500;
private int lastAssignedEmpNum = 500;
public static int lastAssignedEmpNum = 500;
2 points
QUESTION 10
You should declare all instance variables as ___.
protected
class
public
private
2 points
QUESTION 11
You have created a Motorcycle class which has a constructor with no parameters. Which of the following statements will construct an object of this class?
Motorcycle myBike;
Motorcycle myBike = new Motorcycle();
myBike.new(Motorcycle);
Motorcycle.new(myBike);
2 points
QUESTION 12
Consider the following code snippet:
public class Vehicle
{
private String type;
private int numAxles;
public Vehicle(String vehicleType, int VehicleAxles) { . . . }
public Vehicle(String vehicleType) { . . . }
}
What is wrong with this code?
There must be a default constructor with no arguments.
A class cannot have more than one constructor.
If a class has more than one constructor, each one should have a unique name.
There is nothing wrong with this code.
2 points
QUESTION 13
Private instance variables ___.
can only be accessed by methods of a different class
can only be accessed by methods of the same class
cannot be accessed by methods of the same class
can only be accessed by the constructor of the class
2 points
QUESTION 14
You have created a Rocket class which has a constructor with no parameters. Which of the following statements will construct an object of this class?
Rocket myRocket;
Rocket myRocket = new Rocket();
myRocket.new(Rocket);
Rocket.new(myRocket);
2 points
QUESTION 15
Consider the following code snippet:
public class AutoRace
{
private int lapCount;
private double totalTime;
. . .
}
Which of the following completeLap methods would correctly track how many laps occurred?
public void completeLap(double lapTime)
{
totalTime = totalTime + lapTime;
}
public void completeLap(double lapTime)
{
totalTime = totalTime + lapTime;
lapCount ++;
}
public void completeLap(double lapTime)
{
totalTime = totalTime + lapTime;
lapCount = lapCount + lapTime;
}
public void completeLap(double lapTime)
{
totalTime = lapCount + lapTime;
}
2 points
QUESTION 16
A method in a class that returns information about an object but does not change the object is called a/an ____ method.
mutator
accessor
void
constructor
2 points
QUESTION 17
Given the following class definition, which of the following are NOT considered part of the class’s public interface?
public class CashRegister
{
public static final double DIME_VALUE = 0.1;
private static int objectCounter;
public void updateDimes(int dimes) {…}
private boolean updateCounter(int counter) {…}
}
objectCounter and updateCounter
DIME_VALUE and objectCounter
DIME_VALUE and updateDimes
updateDimes and updateCounter
2 points
QUESTION 18
You have created a Coin class and a Purse class. Which of the following methods will correctly add a Coin object to an array list named coins in the Purse class?
public void add(Coin aCoin)
{
coins.add(new Coin(aCoin));
}
public void add(Coin aCoin)
{
coins.add(aCoin);
}
public void add(Coin aCoin)
{
coins.addItem(new Coin(aCoin));
}
public void add(Coin aCoin)
{
coins.addItem(aCoin);
}
2 points
QUESTION 19
Which of the following statements about classes is correct?
When programmers work with an object of a class, they do not need to know how the object stores its data or how its methods are implemented.
When programmers work with an object of a class, they must understand how the object stores its data and how its methods are implemented.
When programmers work with an object of a class, they must understand only how the object stores its data.
When programmers work with an object of a class, they must understand only how the object's methods are implemented.
2 points
QUESTION 20
Given the following class:
public class Coin
{
private String coinName;
private double coinValue;
. . .
}
Consider the following code snippet that utilizes the Coin class:
Coin coin1 = new Coin("dime", 0.10);
Coin coin2 = coin1;
coin2.setValue(0.15);
Which of the following statements is correct?
coin1 has a value of 0.10 and coin2 has a value of 0.15.
coin1 and coin2 both have the value of 0.10.
coin1 and coin2 both have the value of 0.15.
coin2 does not have any data in the coinName variable
public void add(Fruit aFruit)
{
fruits.add(new Fruit(aFruit));
}
public void add(Fruit aFruit)
{
fruits.add(aFruit);
}
public void add(Fruit aFruit)
{
fruits.addItem(new Fruit(aFruit));
}
public void add(Fruit aFruit)
{
fruits.addItem(aFruit);
}
Explanation / Answer
I have assumed that 4 parts of the answer as the a,b,c,d. and given the answers such that.
1)b 2)b 3)d 4)b 5)a 6)a 7)c 8)a 9)a 10)c 11)b 12)d 13)b 14)b 15)b 16)a 17)d 18)b 19)c 20)d
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.