CIS 340 quiz 4
In java, methods must include all of the following except
A call to another method
Every method does not need
A return value
3 principles of object oriented programming
Abstraction, encapsulation, modularity
How do you specify that a parameter within a method header is mandatory or required? Explain in a sentenance or two
All parameters are required by default, Nothing special needs to be done to make a parameter mandatory. Just declare the parameter with its data type and identifier, and its required by default.
The code between a pair of curly braces in a method is a
Block
A constructor _______ parameters
Can recieve
A program or class that instantiates objects of another prewritten class is an
Class client
A public static method named computeSum() is located in ClassA. To call the method from within ClassB, use the statement
ClassA.computeSum();
Parameters are specified in a method declaration as a
Comma-separated list of variable declarations
An example of instantiation
Dog myDog = new Dog();
An objects data items are also known as
Fields
The nonstatic data components of a class often are referred to as the ________ of that class
Instance variables
Nonambigious, overloaded methods must have the same
Name
If you use the automatically supplied default constructor when you create an object
Numeric fields are set to 0 (zero)
If you create a class that contains one method, and instantiate two objects, you usually store _____ for use with the objects
One copy of the method
A method variable ______ a class variable with the same name
Overrides
The portion of a program within which you can reference a variable is the variable's
Scope
If a class is named Student, the class constructor name is
Student()
Usually, you want each instantiation of a class to have its own copy of
The data fields
If you declare a variable as an instance variable within a class, and you declare and use the same variable name within a method of the class, then within the method
The variable used inside the method takes precedence
True or false, method calls can be nested, i.e. method calls can be placed inside other method calls
True
You can declare variables with the same name multiple times
Within a method, in different blocks of the method
If a method is written to receive a double parameter, and you pass an integer to the method, then the method will
Work correctly, but be promoted to a double
Every method must contain
a return type
The keyword final used within a variable declaration indicates
a symbolic constant
Which of the following is a correct call to a method declared as public static void aMethod(char code)?
aMethod('Q');
Suppose you declare an object as Book myJournal; before you store data in myJournal, you
also must explicitly allocate memory for it
The body of a class is always written
between curly braces
The method public static boolean testValue(int response) returns ____
boolean value
A constructor _________ overloaded
can be
The this reference
can be used implicitly
The method with the declaration public static char procedure(double d) has a method type of
char
Variables that are shared by every instantiation of a class are
class variables
Assume there is a method called isPreferredCustomer. The method requires one argument of type String, which represents a customer ID number. The method returns a boolean indicating if that customer is preferred or not. Write code to call the method isPreferredCustomer and pass it the string literal 12345678 as an argument. If the customer is a preferred customer, set the variable deliveryFee to zero. Assume deliveryFee is already declared as a variable as follows: double deliveryFee = 0.0;
if ( isPreferredCustomer(String '12345678') ) deliveryFee = 0;
The concept of allowing a class's private data to be changed only by a class' own methods is known as
information hiding
The method with the declaration public static int aMethod(double d) is a method type of
int
You send messages or information to an object through its
methods
When a block exists within another block, the blocks are
nested
Methods that you reference with individual objects are
nonstatic
Java classes are stored in a folder or
package
All method declarations contain
parenthesis
An example of an access modifier is ___
private
Most class data fields are
private
Which method declaration below has a method signature different than the method below? private static int ProcessInput(int a, double b, int c)
private static int ProcessInput(double a, int b, int c)
Write a method setSpeed, which is private and static. IT should accept one parameter called speed, of type double. setSpeed does not return a value. The body of setSpeed method should contain one printf method, which prints one line to the console and tells the user that the speed has been set to the new speed. Assume now that you are working in the main method of the class Car and the setSpeed method is in the same class. Call the setSpeed method. For the parameter speed, supply an argument of an appropriate data type such that you are setting the speed to six miles an hour.
private static void double setSpeed(double speed) { System.out.printf("speed has been set to %f", speed); } setSpeed(6.0);
Which of the following method declarations is correct for a static method named displayFacts() if the method receives an int argument?
public static void displayFacts(int data)
Declare a method called calculateSalesTax, which accepts two parameters: a tax rate and a purchase amount. Example values of tax rate are 0.08 and 0.10. Example values of purchase amounts are 399.99 and 14. Tax rate amounts should be verified. If they are lower than 7.5%, the method should use a default rate of 7.5% by overwriting the value supplied as a parameter. The method should return the total sales tax, which is calculated as the purchase amount times the tax rate.
public static void double calculateSalesTax(double taxRate, double purchaseAmount) { double totalSalesTaxRate; double totalTaxRate; if(taxRate < 0.075) taxRate =0.075; totalSalesTaxRate = totalTaxRate + taxRate*purchaseAmount; return totalSalesTaxRate;
Which of the following could be the last legally coded line of a method declared as public static int getVal(double sum)?
return 77;
A method's type is the same as its
return type
Which of the following statements determines the square root of a number and assigns it to the variable s?
s = Math.sqrt(number);
A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?
showResults(12.2, 67);
A return type of ___ is specified for a method that does not return a value
void