Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 5 Defining Classes II Multiple Choice 1) 2) 3) 4) 5) 6) 7) 8) 9) A static method is one that can be used with a _____________. instance variable local variable global variable the class name as a calling object Static variables are often used: in arithmetic expressions to communicate between objects within looping structures all of the above Only ______ copy/copies of a static variable are available to objects of a class. one two three none of the above All of these are methods of Java’s Math class except: pow min random toString The Math method that returns the nearest whole number that is greater than or equal to its argument is: round ceil floor all of the above All of the following are wrapper classes except: String Integer Character Double Converting from a value of primitive type to a corresponding object of its associated wrapper class is called: Boxing Unboxing Converting Reinstantiating The conversion from an object of a wrapper class to a value of its associated primitive type is called: Boxing Unboxing Converting Reinstantiating The method trim of the String class trims off: Leading white space Trailing white space 10) 11) 12) 13) 14) 15) 16) 17) Leading and trailing white space Blanks An example of secondary memory is: RAM ROM hard disk all of the above When you use the assignment operator with variables of a class type, you are assigning a: value primitive type local variable reference null can be used: to indicate a variable has no real value in a Boolean expression with == as a placeholder all of the above A copy constructor has _________ parameters. zero one two three A condition that allows a programmer to circumvent the private modifier and change the private instance variable is called: a copy constructor a privacy leak a class invariant an anonymous object A class that contains public methods that can change the data in the object of a class is called a/an: mutable class immutable class invariant class none of the above To create a package, you must add a package statement at the ____________ of each class file. beginning end before each method signature after the import statements The program included in the Java SDK that allows a programmer to separate the class interface from the class implementation is called: javac java javadoc none of the above 18) Javadoc requires a comment to be delimited by _________ to be included in the extracted class interface. // // /* */ /** */ ““ True/False 1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) In a static method, you may use the this parameter either explicitly or implicitly. A main method can be placed inside a class definition. You may use methods of the Math class without an import statement. Wrapper classes provide a class type corresponding to each of the primitive types so that you can have class types that behave somewhat like primitive types. All versions of Java support automatic boxing. Wrapper classes are provided for all primitive Java types except Boolean. A bit may have the value of either a 1 or 0. Primitive types are reference types. A class invariant is a statement that is always true for every object of the class. You should avoid the use of null as an argument to a method. The String class is a mutable class. To use a package, the program must contain an import statement that names the package. Deprecated methods should be used in new Java code. Short Answer/Essay 1) 2) Write a statement that creates and initializes a static variable named salesTax to 7.59. Write a statement that creates a constant variable named TAX_RATE. The tax rate is 8.25%. 3) 4) 5) 6) Write ONE Java statement that computes and displays the value of 25. Write ONE Java statement that computes and displays a random number between 1 and 25. Define boxing and unboxing. Write a complete Java program that prompts the user for a number and prints back the integer as well as floating point values to the console. Write a Java method that returns true if and only if a character is a digit or a letter. The method should display appropriate feedback to the console. Explain in detail how main memory works. How many bytes are contained within 16-bits, 32-bits, 64-bits? When used with objects, what is the equality ( == ) operator really comparing? Does an object created with a copy constructor reference the same memory location that the original object references? Explain. Explain how a package is named in Java. Create a Java class named Book with instance variables title, author, ISBN, and yearPublished. Include javadoc style comments to describe your interface. Such a class would normally have methods, but you are not required to supply any methods. Add accessor and mutator methods to the Book class created in question #13. Add a constructor and a copy constructor to the Book class created in question #13. 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) What is the purpose of Java’s wrapper classes? Write a complete Java program that prompts the user for a phrase. The program converts and displays the phrase in uppercase letters. Write a complete Java program using the StringTokenizer class that computes and displays the average of a list of grades read from the command line. Each grade should be entered on the same line separated by commas. Enter signifies the end of the input.