Unformatted text preview:

Chapter 5 Defining Classes II Multiple Choice)1 A static method is one that can be used with a _____________.()a instance variable()b local variable()c global variable()d the class name as a calling object)2 Static variables are often used:()a in arithmetic expressions()b to communicate between objects()c within looping structures()d all of the above)3 Only ______ copy/copies of a static variable are available to objects of a class.()a one()b two()c three()d none of the above)4 All of these are methods of Java’s Math class except:()a pow()b min()c random()d toString)5 The Math method that returns the nearest whole number that is greater than or equal to its argument is:()a round()b ceil()c floor()d all of the above)6 All of the following are wrapper classes except:()a String()b Integer()c Character()d Double)7 Converting from a value of primitive type to a corresponding object of its associated wrapper class is called:()a Boxing()b Unboxing()c Converting()d Reinstantiating)8 The conversion from an object of a wrapper class to a value of its associated primitive type is called:()a Boxing()b Unboxing()c Converting()d Reinstantiating)9 The method trim of the String class trims off:()a Leading white space()b Trailing white space()c Leading and trailing white space()d Blanks)10 An example of secondary memory is:()a RAM()b ROM()c hard disk()d all of the above)11 When you use the assignment operator with variables of a class type, you are assigning a:()a value()b primitive type()c local variable()d reference)12 null can be used:()a to indicate a variable has no real value()b in a Boolean expression with ==()c as a placeholder()d all of the above)13 A copy constructor has _________ parameters.()a zero()b one()c two()d three)14 A condition that allows a programmer to circumvent the private modifier and change the private instance variable is called:()a a copy constructor()b a privacy leak()c a class invariant()d an anonymous object)15 A class that contains public methods that can change the data in the object of a class is called a/an:()a mutable class()b immutable class()c invariant class()d none of the above)16 To create a package, you must add a package statement at the ____________ of each class file.()a beginning()b end()c before each method signature()d after the import statements)17 The program included in the Java SDK that allows a programmer to separate the class interface from the class implementation is called:()a javac()b java()c javadoc()d none of the above)18 Javadoc requires a comment to be delimited by _________ to be included in the extracted class interface.()a // //()b /* */()c /** */()d “ “ True/False)1 In a static method, you may use the this parameter either explicitly or implicitly.)2 A main method can be placed inside a class definition.)3 You may use methods of the Math class without an import statement.)4 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.)5 All versions of Java support automatic boxing.)6 Wrapper classes are provided for all primitive Java types except Boolean.)7 A bit may have the value of either a 1 or 0.)8 Primitive types are reference types.)9 A class invariant is a statement that is always true for every object of the class.)10 You should avoid the use of null as an argument to a method.)11 The String class is a mutable class.)12 To use a package, the program must contain an import statement that names the package.)13 Deprecated methods should be used in new Java code. Short Answer/EssayWrite 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%.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.)1 What is the purpose of Java’s wrapper classes?)2 Write a complete Java program that prompts the user for a phrase. The program converts and displays the phrase in uppercase letters.)3 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.Chapter 5Defining Classes II Multiple Choice)1 A static method is one that can be used with a _____________.()a instance variable()b local variable()c global variable()d the class name as a calling object)2 Static variables are often used:()a in arithmetic expressions()b to communicate between objects()c within looping structures()d all of the above)3 Only ______ copy/copies of a static variable are available to objects of a class.()a one()b two()c three()d none of the above)4 All of these are methods of Java’s Math class except:()a pow()b min()c random()d toString)5 The Math method that returns the nearest whole number that is greater than or equal to its argument is:()a round()b ceil()c floor()d all of the above)6 All of the following are wrapper classes except:()a String()b Integer()c Character()d Double)7 Converting from a value of primitive type to a corresponding object of its associated wrapper class is called:()a Boxing()b Unboxing()c Converting()d Reinstantiating)8 The conversion from an object of a wrapper


View Full Document

SJU CSC 3405 - Lecture notes

Download Lecture notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?