Question: 1.Reference-type variables (called references) store _____ in memory. the value of an object a copy of an object the memory location of an object the
1.Reference-type variables (called references) store _____ in memory.
| | the memory location of an object |
2. A contractor uses a blueprint to build a house. An object is similar to
3. Set methods are also commonly called _____ methods.
4.Which of the following statements is false?
| | By convention class names begin with an uppercase letter, and method and variable names begin with a lowercase letter. |
| | Instance variables exist before methods are called on an object, while the methods are executing and after the methods complete execution. |
| | A class normally contains one or more methods that manipulate the instance variables that belong to particular objects of the class. |
| | Private instance variables are directly accessible outside of the class that contains them. |
5.A class named Grades has a public method named calcAvg. Which statement is valid regarding an instance of that class that is created as Grades myGrades = new Grades();
6. A key part of enabling the JVM to locate and call method main to begin the apps execution is the _____ keyword, which indicates that main can be called without first creating an object of the class in which the method is declared.
7. The format specifier %.2f specifies that two digits of precision should be output _____ in the floating-point number.
| | to the left of the decimal point |
| | to the right of the decimal point |
8. Which statement is correct to complete the setNum method below?
public class Test { private int num; public void setNum(int n) { //what goes here } }
9. What error, if any, is in the following code?
int num; Scanner input = new Scanner(System.in); System.out.print(Enter a number: ); num = input.nextLine();
| | The variable num must have an initial value. |
| | The Scanner object must be created before num is declared. |
| | The method nextInt must be used instead of nextLine. |
| | This code is correct as is. |
10. What does the following code display?
public class RentalApp { public static void main(String[] args) { Rental r = new Rental(); r.setNumOfPersons(5); r.addPerson(); r.addPerson(); System.out.println(r.getNumOfPersons()); } } public class Rental { private int numOfPersons; public int getNumOfPersons() { return numOfPersons; } public void setNumOfPersons(int numOfPersons) { this.numOfPersons = numOfPersons; } public void addPerson() { numOfPersons = numOfPersons + 1; } }