CSC230 midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What file suffix is used for java compiled byte code?

.class

What is the value of the count variable after the execution of the given code snippet? ArrayList<Integer> num = new ArrayList<Integer>(); num.add(1); num.add(2); num.add(1) int count = 0; for (int i = 0; i < num.size(); i++) { if (num.get(i) % 2) == 0) { count++): } }

1

List 3 advantages of pairwise programming.

1. Increased productivity 2. Fewer defects 3. Higher morale 4. Knowledge transfer 5. Higher quality code

According to the Google Java Style Guide, the maximum number of characters in a single line should be ?

100

How many spaces should the unit of indentation be according to the Google Java Style Code Conventions?

2

What is the output of the given code snippet? int [] mynum = new int[5]; for (int i = 1; i < 5; i++) { mynum[i] = i + 1; System.out.print(mynum[i]); }

2345

Consider the following code snippet: int [][] numarray = { { 3, 2, 3 }, { 0, 1, 0 } }: System.out.print(numarray[0][0]); System.out.print(numarray[1][0]); What is the output of the given code snippet?

30

What is the output of the following code snippet? int [] myarray = { 10, 20, 30, 40, 50 }; System.out.print(myarray[2]); System.out.println(myarray[3]);

3040

How many elements can be stored in an array of dimension 2 by 3?

6

What is the output of the code snippet below? int [][] arr = { { 1, 2, 3, 0 }, { 4, 5, 6, 0 }, { 3, 2, 1, 3 } }; int val = arr[1][2] + arr[1][3]; System.out.println(val);

6

What will be printed by the statements below? int [] values = { 4, 5, 6, 7 }; values[0] = values[3]; values[3] = values[0]; for (int i = 0; i < values.length; i++) { System.out.print(values[i] + " "); }

7 5 6 7

What percentage of the lifetime cost of a piece of software goes to maintenance?

80

List at least 3 principles or practices discussed in the pair wise article that you need to follow to make pair wise programming successful on your first project.

Play fair - Share the keyboard. Change drivers Stay focused. Both should be actively engaged. Ego less programming. Joint ownership of all work and defects. Continuous discussion during development. Share everything. Both are equal participants. All code is developed together or if code is developed individually then code must be jointly reviewed.

A class named CurrencyTranslator would most probably fall into which of the following class categories? Select one: a. Actor classes b. Starter classes c. Abstract entities d. Utility classes

a

Complete the following code snippet with the correct enhanced for loop so it iterates over the array without using an index variable. String [] arr = { "abc", "def", "ghi", "jkl" }; __________________________________ { System.out.println(str); } Select one: a. for (String str: arr) b. for (str : String arr) c. for (str [] : arr) d. for (arr[] : str)

a

Consider the following code snippet that appears in a subclass: public void deposit(double amount) { transactionCount = transactionCount + 1; deposit(amount); } Which of the following statements is true? Select one: a. This method will call itself. b. This method calls a public method in its subclass. c. This method calls a private method in its superclass. d. This method calls a private method in its subclass.

a

Consider the following code snippet. File inputFile = new File("dataIn.txt"); Scanner in = new Scanner(inputFile); while (in.hasNext()) { String in = in.next(); } Which of the following statements about this code is correct? Select one: a. This code will read in a word at a time from the input file. b. This code will read in the entire input file in one operation. c. This code will read in a line at a time from the input file. d. This code will read in a character at a time from the input file.

a

Consider the following code snippet. Scanner inputFile = new Scanner("dataIn.txt"); Which of the following statements is correct? Select one: a. This code will not open a file named "dataIn.txt", but will treat the string "dataIn.txt" as an input value. b. This code will create a new file named "dataIn.txt". c. This code will open an existing file named "dataIn.txt" for reading. d. This code will open a file named "dataIn.txt" for writing.

a

Consider the following code snippet. public interface Measurable { double getMeasure(); } public Coin implements Measurable { ... public double getMeasure() { return value; } } public class DataSet { ... public void add() { ... } } public class BankAccount { ... public void add() { ... } } Which of the following statements is true? Select one: a. Coin dime = new Coin(0.1, "dime"); Measurable x = dime; b. Coin dime = new Coin(0.1, "dime"); DataSet x = dime; c. Coin dime = new Coin(0.1, "dime"); DataSet x = (Measurable) dime; d. Coin dime = new Coin(0.1, "dime"); BankAccount x = dime;

a

Consider the following code snippet: Scanner in = new Scanner(. . .); while (in.hasNextLine() { String input = in.nextLine(); System.out.println(input); } Which of the following statements about this code is correct? Select one: a. This code will read in an entire line from the file in each iteration of the loop. b. This code will read in the entire contents of the file in a single iteration of the loop. c. This code will read in a single word from the file in each iteration of the loop. d. This code will read in a single character from the file in each iteration of the loop.

a

Consider the following code snippet: System.out.println("%-12s%8.2f", description, totalPrice); Which of the following statements is correct? Select one: a. This code will produce 2 columns, with the description field left justified and the totalPrice field right justified. b. This code will produce 2 columns, with the description field right justified and the totalPrice field right justified. c. This code will produce 2 columns, with the description field right justified and the totalPrice field left justified. d. This code will produce 2 columns, with the description field left justified and the totalPrice field left justified.

a

Consider the following code snippet: Vehicle aVehicle = new Auto(4, "gasoline"); String s = aVehicle.toString(); Assume that the Auto class inherits from the Vehicle class, and neither class has an implementation of the toString() method. Which of the following statements is correct? Select one: a. The toString() method of the Object class will be used when the code is executed. b. The toString() method of the String class will be used when this code is executed. c. The code will not compile because there is no toString() method in the Vehicle class. d. The code will not compile because there is no toString() method in the Auto class.

a

Consider the following code snippet: public class Inventory implements Measurable { .... public double getMeasure { return onHandCount; } } Why is it necessary to declare getMeasure as public? Select one: a. All methods in a class are not public by default. b. All methods in an interface are private by default. c. It is necessary only to allow other classes to use this method. d. It is not necessary to declare this method as public.

a

Consider the following code snippet: public interface Sizable { ... double getSize() { return containerVolume; } } What is wrong with this code? Select one: a. The getSize() method must not have any code within it. b. The getSize() method must include the implements keyword. c. The getSize() method must be declared public. d. The getSize() method must be declared as private.

a

Consider the following code snippet: throw new IllegalArgumentException("This operation is not allowed"); Which of the following statements about this code is correct? Select one: a. This code constructs an object of type IllegalArgumentException and throws the object. b. This code throws an existing IllegalArgument object. c. This code constructs an object of type IllegalArgumentException and reserves it for future use. d. This code will not compile.

a

If you have multiple classes in your program that have implemented the same interface in different ways, how is the correct method executed? Select one: a. The Java virtual machine must locate the correct method by looking at the class of the actual object. b. The compiler must determine which method implementation to use. c. The method must be qualified with the class name to determine the correct method. d. You cannot have multiple classes in the same program with different implementations of the same interface.

a

It may be necessary to "grow" an array when reading inputs because Select one: a. the number of inputs may not be known in advance. b. arrays in Java must be resized after every 100 elements. c. arrays are based on powers of two. d. the only alternative is a bounds exception.

a

The Java compiler requires that your program handle which type of exceptions? Select one: a. Checked b. Fatal c. Unchecked d. Server

a

The Scanner class's __________________ method is used to specify a pattern for word boundaries when reading text. Select one: a. useDelimiter() b. usePattern() c. setDelimiter() d. setPattern()

a

The enhanced for loop Select one: a. is convenient for traversing all elements in an array. b. is convenient for traversing elements in a partially filled array. c. is only used for arrays of integers d. is used to initialize all array elements to a common value.

a

The following statement gets an element from position 4 in an array: x = a[4]; What is the equivalent operation using an array list? Select one: a. x = a.get(4); b. x = a.get(); c. x = a.get[4]; d. x = a[4];

a

Under what condition will the PrintWriter constructor generate a FileNotFoundException? Select one: a. If the output file cannot be opened or created due to a security error. b. If the output file does not exist. c. If the output file already exists, but has data in it. d. If the output file already exists, but is empty.

a

Vehicle --> AirVehicle, LandVehicle (--> Auto), WaterVehicle Which of the following statements is correct? Select one: a. Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class. b. Auto class inherits from LandVehicle class, and Vehicle class inherits from LandVehicle class. c. LandVehicle class inherits from Auto class, and LandVehicle class inherits from Vehicle class. d. LandVehicle class inherits from Auto class, and Vehicle class inherits from LandVehicle class.

a

Which of the following can potentially be changed when implementing an interface? Select one: a. The parameters of a method in the interface. b. The name of the method in the interface. c. The return type of a method in the interface. d. You cannot change the name, return type, or parameters of a method in the interface.

a

Which of the following indicates that a class named ClassA class is a superclass of the ClassB class? Select one: a. public class ClassB extends ClassA b. public class ClassB implements ClassA c. public class ClassA extends ClassB d. public class ClassA implements ClassB

a

Which of the following is one of the most popular testing frameworks? Select one: a. JUnit b. JUnitTest c. JTester d. JQATester

a

Which of the following represents a good strategy regarding cohesion and coupling? Select one: a. Maximize cohesion and remove unnecessary coupling. b. Minimize cohesion and remove unnecessary coupling c. Maximize cohesion and coupling d. Minimize cohesion and maximize coupling

a

Which of the following statements about abstract methods is true? Select one: a. An abstract method has a name, parameters, and a return type, but no code in the body of the method. b. An abstract method has parameters, a return type, and code in its body, but has no defined name. c. An abstract method has a name, a return type, and code in its body, but has no parameters. d. An abstract method has only a name and a return type, but no parameters or code in its body.

a

Which of the following statements is true regarding method parameters in Java? Select one: a. All method parameters use the call-by-value mechanism. b. Only method parameters of primitive type use the call-by-value mechanism. c. All method parameters use the call-by-reference mechanism. d. Only method parameters of object type use the call-by-value mechanism.

a

Which of the following statements regarding static methods is true? Select one: a. The textbook recommends that you minimize the use of static methods. b. The textbook recommends that static methods should be liberally used within classes. c. Use of static methods usually leads to good object oriented design. d. Static methods can be easily evolved to add more functionality.

a

Which return value of the JFileChooser object's showOpenDialog method indicates that a file was chosen by the user at run time? Select one: a. APPROVE_OPTION b. CANCEL_OPTION c. OK_OPTION d. SELECTED_OPTION

a

Why is a static variable also referred to as a class variable? Select one: a. There is a single copy available to all objects of the class. b. It is encapsulated within the class. c. Each class has one and only one static variable. d. It is stored in the separate class area of each object.

a

All java source files should begin with a comment that lists a. date b. version information c. copyright d. classname or filename

a, b, c, d

A class that represents the most general entity in an inheritance hierarchy is called a/an ________________________. Select one: a. Default class. b. Superclass. c. Subclass d. Inheritance class.

b

Consider the following code snippet: String [] data = { "abc", "def", "ghi", "jki" }; String [] data2; Which statement copies the data array to the data2 array? Select one: a. data2 = Arrays.copyOf(data, data2.length); b. data2 = Arrays.copyOf(data, data.length); c. data2 = Arrays.copyOf(data, data.size()); d. data2 = Arrays.copyOf(data);

b

General Java variable naming conventions would suggest that a variable named NICKEL_VALUE would most probably be declared using which of the following combinations of modifiers? Select one: a. public void final b. public static final double c. private static double d. private static

b

Identify the correct statement for defining an integer array named numarray of ten elements. Select one: a. int [] numarray = new int[9]; b. int [] numarray = new int[10]; c. int [] numarray; d. int numarray[10];

b

In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable? Select one: a. Call-by-reference b. Call-by-value c. Call-by-precondition d. Call-by-object

b

In which of the following cases could a static variable be declared as something other than private? Select one: a. When it will be accessed by multiple objects. b. When implementing static constants. c. When declared inside a private method. d. Static variables should never be declared as anything but private.

b

The String class is an example of which of the following types of classes? Select one: a. Static class b. Immutable class c. Abstract class d. Mutable class

b

To ensure that an instance variable can only be accessed by the class that declared it, the variable should be declared as ________________. Select one: a. public b. private c. protected d. final

b

To override a superclass method in a subclass, the subclass method ____________. Select one: a. Must use a different name. b. Must use the same method name and the same parameter types. c. Must use a different method name and the same parameter types. d. Must use a different method name and different parameter types.

b

Under which condition will the Scanner constructor generate a FileNotFoundException? Select one: a. If the input file cannot be opened due to a security error. b. If the input file does not exist. c. If the input file already exists, but has data in it. d. If the input file already exists, but is empty.

b

When an array myArray is only partially filled, how can the programmer keep track of the current number of elements? Select one: a. access myArray.length() b. maintain a companion variable that stores the current number of elements c. access myArray.currentElements() d. access myArray.length() - 1;

b

When the order of the elements is unimportant, what is the most efficient way to remove an element from an array? Select one: a. Delete the element and move each element after that one to a lower index. b. Replace the element to be deleted with the last element in the array. c. Replace the element to be deleted with the first element in the array. d. Replace the element with the next element.

b

Which of the following is true regarding class and interface types? Select one: a. You can convert from a class type to any interface type that is in the same package as the class. b. You can convert from a class type to any interface type that the class implements. c. You can convert from a class type to any interface type that the class defines. d. You cannot convert from a class type to any interface type.

b

Which of the following statements about comparing objects is correct? Select one: a. The equals method is used to compare whether two references are to the same object. b. The equals method is used to compare whether two objects have the same contents. c. The == operator is used to compare whether two objects have the same contents. d. The equals method and the == operator perform the same actions.

b

Which of the following statements about inheritance is correct? Select one: a. You can always use a superclass object in place of a subclass object. b. You can always use a subclass object in place of a superclass object. c. A superclass inherits data and behavior from a subclass. d. A superclass inherits only behavior from a subclass.

b

Which of the following would be an appropriate name for a game-related class? Select one: a. CompletedLevelOne b. InitialLevel c. ResetCurrentLevel d. AscentToFinalLevel

b

Which statement about methods in an interface is true? Select one: a. All methods in an interface are automatically private. b. All methods in an interface are automatically public. c. All methods in an interface are automatically static. d. All methods in an interface must be explicitly declared as private or public.

b

Which statement is true about the code snippet below? ArrayList<String> names = new ArrayList<String>(); names.add("John"); names.add("Jerry"); ArrayList<String> friends = new ArrayList<String>(names); names.add("Harry"); Select one: a. The final size of names is 2; the final size of friends is 3 b. The final size of names is 3; the final size of friends is 2 c. The final size of names is 1; the final size of friends is 2 d. The final size of names is 3; the final size of friends is 3

b

Why can't Java methods change parameters of primitive type? Select one: a. Java methods can have no actual impact on parameters of any type. b. Parameters of primitive type are considered by Java methods to be local variables. c. Parameters of primitive type are immutable. d. Java methods cannot accept parameters of primitive type.

b

You are creating a class inheritance hierarchy about motor vehicles that will contain classes named Vehicle, Auto, and Motorcycle. Which of the following statements is correct? Select one: a. Vehicle should be the default class, while Auto and Motorcycle should be the subclasses. b. Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses. c. Vehicle should be the subclass, while Auto and Motorcycle should be the superclasses. d. Vehicle should be the subclass, while Auto and Motorcycle should be the default classes.

b

You have defined an interface called Sizable, and a class named PhotoImage which implements the Sizable interface. Which of the following is a valid Java statement for using the Sizable interface? Select one: a. Sizable newImage = (Sizeable) PhotoImage(); b. Sizable newImage = new PhotoImage(); c. PhotoImage newImage = new Sizeable(); d. Sizable newImage = new Sizeable();

b

Your program needs to store an integer sequence of unknown length. Which of the following is most suitable to use? Select one: a. An array declared as int [] marks; b. A array list declared as ArrayList<Integer> marks = new ArrayList<Integer>(); c. An array declared as int marks[10000]; d. An array declared as int marks[10];

b

What is the result of executing this code snippet? int [] marks = { 90, 45, 67 }; for (int i = 0; i <= 3; i++) { System.out.println(marks[i]); }

bounds error

Consider the following code snippet, assuming that filename represents the name of the output file and writeData outputs the data to that file: try (PrintWriter outputFile = new PrintWriter(filename)) { writeData(outputFile); } Which of the following statements about this code is correct? Select one: a. The close method of the outputFile object will be automatically invoked when the try block ends, but only if no exception occurred. b. The program will terminate with an unhandled exception if the PrintWriter constructor fails. c. The close method of the outputFile object will be automatically invoked when the try block ends, whether or not an exception has occurred. d. The close method of the outputFile object will be automatically invoked when the try block ends, but only if an exception occurs.

c

Consider the following code snippet: public class Coin { private String name; . . . public boolean equals(Object otherCoin) { return name.equals(otherCoin.name): } } What is wrong with this code? Select one: a. The return statement should use the == operator instead of the equals method. b. The parameter in the equals method should be declared as Coin otherCoin. c. otherCoin must be cast as a Coin object before using the name.equals(otherCoin.name) statement. d. There is nothing wrong with this code.

c

Consider the following code snippet: public class Inventory implements Measurable { .... double getMeasure() { return onHandCount: } } What is wrong with this code? Select one: a. The getMeasure() method must be declared as private. b. The getMeasure() method must include the implements keyword. c. The getMeasure() must be declared as public. d. The getMeasure() method must not have any code within it.

c

If you do not include a package statement at the top of the source file, its class will be placed in which package? Select one: a. java.lang b. java.util c. the default package, which has no name d. java.awt

c

Insert the missing code in the following code fragment. This fragment is intended to read an input file. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = __________________; . . . } Select one: a. new Scanner(inputFileName) b. new Scanner(outputFileName) c. new Scanner(inputFile) d. new Scanner(System.in)

c

Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file. Scanner in = new Scanner( . . . ); in.useDelimiter(""); while (in.hasNext()) { char ch = __________________; System.out.println(ch); } Select one: a. in.getNext(); b. in.next(); c. in.next().charAt(0); d. in.nextChar()

c

To test whether an object belongs to a particular class type , use ___________________. Select one: a. the this reserved word. b. the subclassOf reserved word. c. the instanceof operator d. the equals method.

c

Under which of the following conditions would the public interface of a class be considered cohesive? Select one: a. All of its features are public and none of its features are static. b. The quality of the public interface is rated as moderate to high. c. All of its features are related to the concept that the class represents. d. It is obvious that the public interface refers to multiple concepts.

c

What is the purpose of the throw statement? Select one: a. It is used to pass arguments to another method. b. It is used to detect an error situation. c. It is used to pass control to an error handler when an error situation is detected. d. It is used to discard erroneous input.

c

What must a subclass do to modify a private superclass instance variable? Select one: a. The subclass must simply use the name of the superclass instance variable. b. The subclass must declare its own instance variable with the same name as the superclass instance variable. c. The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable. d. The subclass must have its own public method to update the superclass's private instance variable.

c

Which annotation is used to mark test methods when using JUnit? Select one: a. @TestMethod b. @TestCode c. @Test d. @JUnitTest

c

Which class category has static methods and constants, but no objects? Select one: a. Real-life entity abstraction b. Actor classes c. Utility class d. Concept class

c

Which method of the JFileChooser object will return the file object that describes the file chosen by the user at runtime? Select one: a. getFile() b. getSelectedFilePath() c. getSelectedFile() d. getFilePath()

c

Which of the following describes an immutable class? Select one: a. A class that has no accessor or mutator methods. b. A class that has no accessor methods, but does have mutator methods. c. A class that has accessor methods, but does not have mutator methods. d. A class that has both accessor and mutator methods.

c

Which of the following is a common use for inner classes? Select one: a. Methods that do not need to be kept secure. b. Utility classes that will be used by multiple classes within the program. c. Utility classes that do not need to be visible elsewhere in the program. d. Classes which many other classes will extend.

c

Which of the following is true regarding subclasses? Select one: a. A subclass inherits methods from its superclass but not instance variables. b. A subclass inherits instance variables from its superclass but not methods. c. A subclass inherits methods and instance variables from its superclass. d. A subclass does not inherit methods or instance variables from its superclass.

c

Which of the following statements about interfaces is NOT true? Select one: a. Interfaces can make code more reusable. b. An interface provides no implementation. c. A class can implement only one interface type. d. Interfaces can reduce the coupling between classes.

c

Which of the following statements about reading and writing text files is correct? Select one: a. You use the Scanner class to read and write files. b. You use the PrintWriter class to read and write text files. c. You use the Scanner class to read text files and the PrintWriter class to write text files. d. You use the Scanner class to write text files and the PrintWriter class to read text files.

c

Which of the following statements about using the PrintWriter object is correct? Select one: a. If the output file already exists, the new data will be appended to the end of the file. b. If the output file already exists, a FileNotFoundException will occur. c. If the output file already exists, the existing data will be discarded before new data are written into the file. d. If the output file does not exist, an IllegalArgumentException will occur.

c

Which of the following statements about white space in Java is correct? Select one: a. In Java, white space includes spaces only. b. In Java, white space includes spaces and tab characters only. c. In Java, white space includes spaces, tab characters and newline characters. d. In Java, white space includes spaces, tab characters, newline characters, and punctuation.

c

Which of the following types of methods are invoked on objects? Select one: a. Static method b. Class method c. Instance method d. Either static or instance methods

c

_____________________ occurs when a single class has several methods with the same name but different parameter types. Select one: a. Casting b. Polymorphism c. Overloading d. Instantiation

c

A method that has no implementation is called a/an _____________________ method. Select one: a. interface b. implementation c. overloaded d. abstract

d

A/an ______________ class defined in a method signals to the reader of your program that the class is not interesting beyond the scope of the method. Select one: a. A class cannot be defined within a method. b. abstract c. interface d. inner

d

Assume the variable numbers has been declared to be an array that has at least one element. Which of the following represents the last element in numbers? Select one: a. numbers[numbers.length]; b. numbers.length c. numbers[-1] d. numbers[numbers.length - 1]

d

Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String atype) { type = atype; } public String getType() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String atype) { ... } } public class Auto extends LandVehicle { public Auto(String atype) { ... } } Which of the following code fragments in NOT valid in Java? Select one: a. Vehicle myAuto = new Auto("sedan"); b. LandVehicle myAuto = new Auto("sedan"); c. Auto myAuto = new Auto("sedan"); d. LandVehicle myAuto = new Vehicle("sedan");

d

Consider the following code snippet: Coin nickel = new Coin(0.1, "nickel"); Measurable meas = nickel.getMeasure(); Assume that the Coin class has implemented the Measurable interface. You now need to convert the meas object back to a Coin object. Which of the following is the correct code to do this? Select one: a. Coin nickelValue = (Coin) meas.getMeasure(); b. Coin nickelValue = meas.getMeasure(); c. Coin nickelValue = meas; d. Coin nickelValue = (Coin) meas;

d

Consider the following code snippet: public class Vehicle { private String manufacturer; public void setVehicleClass(double numberAxles) { ... } } If a motorcycle class is created as a subclass of the Vehicle class,which of the following statements is correct? Select one: a. A Motorcycle object inherits and can directly use both the instance variable manufacturer and the method setVehicleClass. b. A Motorcycle object inherits and can directly use the instance variable manufacturer but not the method setVehicleClass. c. A Motorcycle object inherits but cannot directly use either the instance variable manufacturer or the method setVehicleClass. d. A Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.

d

If a subclass contains a method with the same name as a method in its superclass, but with different parameter types, the subclass is said to _______________ the method of the superclass. Select one: a. implement b. inherit c. override d. overload

d

Judging by the name of the method, which of the following methods would most likely be a mutator method? Select one: a. getListOfDeposits b. findAccountBalance c. isOverdrawn d. deposit

d

The ____________________ method of the Character class will indicate if a character contains white space. Select one: a. isValid() b. getChar() c. hasNext() d. isWhiteSpace()

d

To use an interface, a class header should include which of the following? Select one: a. The keyword extends and the name of the abstract method in the interface. b. The keyword extends and the name of the interface. c. The keyword implements and the name of an abstract method in the interface d. The keyword implements and the name of the interface.

d

What role does an interface play when using a mock class? Select one: a. The mock class should be an interface that will be implemented by the real class. b. The real class should be an interface that will be implemented by the mock class. c. Interfaces are not involved when using mock classes. d. An interface should be implemented by both the real class and the mock class to guarantee that the mock class accurately simulates the real class when used in a program.

d

When reading words with a Scanner object, a word is defined as __________. Select one: a. Any sequence of characters consisting of letters only. b. Any sequence of characters consisting of letters, numbers, and punctuation symbols only. c. Any sequence of characters consisting of letters and numbers only. d. Any sequence of characters that is not white space.

d

Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface? Select one: a. JOptionPane b. JFileOption c. JFilePane d. JFileChooser

d

Which code snippet calculates the sum of all the elements in even positions in an array? Select one: a. int sum = 0; for (int i = 1; i < values.length; i = i + 2) { sum++; } b. int sum = 0; for (int i = 0; i < values.length; i++) { sum++; } c. int sum = 0; for (int i = 0; i < values.length; i++) { sum = sum + values[i]; } d. int sum = 0; for (int i = 0; i < values.length; i = i + 2) { sum = sum + values[i]; }

d

Which of the following code statements about exception handling is recommended by the textbook? Select one: a. All exceptions should be handled where they are first detected. b. All exceptions should be handled at the top of the chain of methods. c. Throw an exception only when the problem can be handled. d. Throw an exception as soon as a problem is detected, but only catch exceptions when the problem can be handled.

d

Which of the following is true regarding subclasses? Select one: a. A subclass that inherits methods from its superclass may not override the methods. b. A subclass that inherits instance variables from its superclass may not declare additional instance variables. c. A subclass may inherit methods or instance variables from its superclass but not both. d. A subclass may inherit methods and instance variables from its superclass, and may also implements its own methods and declare its own instance variables.

d

Which of the following statements about converting between types is true? Select one: a. When you cast number types, you take a risk that an exception will occur. b. When you cast number types, you will not lose information. c. When you cast object types, you take a risk of losing information. d. When you cast object types, you take a risk that an exception will occur.

d

Which of the following statements about exception handling is correct? Select one: a. Statements that may cause an exception should be placed within a catch block. b. The main method of a Java program will handle any error encountered in the program. c. Statements that may cause an exception should be placed within the throws block. d. Statements that may cause an exception should be placed within the try block.

d

Which of the following statements about interfaces is NOT true? Select one: a. Interfaces can make code more reusable. b. Interface types can be used to define a new reference data type. c. Interface types can be used to express common operations required by a service. d. Interfaces have both private and public methods.

d

Which of the following statements about interfaces is true? Select one: a. You can define an interface variable that refers to an object of any class in the same package. b. You cannot define a variable whose type is an interface. c. You can instantiate an object from an interface class. d. you can define an interface variable that refers to an object only if the object belongs to a class that implements the interface.

d

Which of the following statements is true relative to classes that will successfully compile? Select one: a. They must have both mutators and accessor methods. b. They must have accessors, and optionally may have mutators. c. They must have mutators, and optionally may have accessors. d. They may have either mutator or accessor methods, or both.

d

Which of the following statements reflects the textbook's recommendations about closing files? Select one: a. Both the input and the output file do not need to be explicitly closed in the program. b. Only the input file must be explicitly closed in the program. c. Only the output file must be explicitly closed in the program. d. Both the input and the output file should be explicitly closed in the program.

d

Which type of method modifies the object on which it is invoked? Select one: a. Constructor method b. Static method c. Accessor method d. Mutator method

d

You wish to implement a call back method for an object created from a system class that you cannot change. What approach does the textbook recommend to accomplish this? Select one: a. Create a new class that mimics the system class. b. Extend the system class. c. Use an inner class in the interface. d. Use a helper class that implements the callback method.

d

____________ can reduce the coupling between classes. Select one: a. Static methods b. Objects c. Abstract methods d. Interfaces

d

Which is the prefered identifier for the naming of a package containing code from elon university for music?

edu.elon.music

To create a subclass, use the _________ keyword.

extends

T/F Google Java Style Guide recommends declaring multiple variables on the same line for efficiency. For example, the declaration of two integers such as int level, size; is preferred over int level; int size;

false

T/F In Javadoc, a @return tag is required for all constructors.

false

T/F In Javadoc, if a class has 3 authors then there should be three @author tags on adjacent lines with the authors listed in alphabetical order.

false

T/F Method names should be verbs in mixed case with the first letter of each word capitalized. Two examples of valid method names are: RunFast(); RunFar();

false

T/F The open brace for a class declaration should occur immediately on the first line after the class declaration. For example: class Sample { int ivar1; double dvar2; Sample(int i, double d) { ivar1 = i; dvar2 = d; } }

false

Consider the following code snippet: public class Demo { Point [] p = new Point[4]; p[0] = new Colored3DPoint(4, 4, 4, Color.BLACK); p[1] = new ThreeDimensionalPoint(2, 3, 3); p[2] = new ColoredPoint(3, 3, Color.RED); p[3] = new Point(4, 4); for (int i = 0; i < p.length; i++) { String s = p[i].toString(); System.out.println("p[" + i + "] : " + s); } return; } The code is an example of _____.

polymorphism

What is the recommended visibility for a instance variable of a class?

private

Which reserved word must be used to call a method of a superclass from within a method of the subclass with the same method name?

super

T/F A blank space should appear after commas in argument lists.

true

T/F A switch statement should have the following form: switch (condition) { case ABC: statements; /* falls through */ case DEF: statements; break; default: statements; break; }

true

T/F According to Google Java Style Guide, declare local variables just before they are used. Don't put variable declarations at the beginning of the block.

true

T/F All binary operators except . should be separated from their operands by spaces.

true

T/F Constructors are member functions that perform initialization when an object is first created. Constructors are always given the same name as the class. For example, a constructor for the class Customer would be Customer().

true

T/F It is a good idea to use parenthesis liberally in expressions involving mixed operators to avoid operator precedence problems.

true

T/F The if-else class of statements should have the following form: if (condition) { statements; } else if (conditions) { statements; } else { statements; }

true

T/F The names of variables declared class constants should be all uppercase with words separated by underscores. An example of a constant is private static final int MIN_WIDTH = 4;

true

T/F To construct an unambiguous package name, you should use a domain name in reverse. If you do not have a domain name, you should use your email address backwards.

true


Kaugnay na mga set ng pag-aaral

Leadership - Ch 9 - MGMT-5370-W01 - SEMINAR

View Set

waves, sound, light, color review

View Set

IHI PS 104 Teamwork and Communication

View Set

Personally Identifiable Information (PII) v4.0

View Set

UCONEXAM22 - Uconnect Customer FAQs

View Set