click below
click below
Normal Size Small Size show me how
COP 3352: Final
Study info for Final
Question | Answer |
---|---|
All import declarations must be placed ____________. | before the class declaration. |
Which of the following segments is a proper way to call the method readata four time? | int i = 0; while(i < 4) { readData(); i = i + 1; } |
Which command executes the Java class file Welcome.class: ____________ | java Welcome |
What does the expression x %= 10 do? | Divides x by 10 and stores the remainder in x. |
End-of-line comments that should be ignored by the compiler are denoted using | Two forward slashes |
_______ models software in terms similar to those that people use to describe real-world objects. | Object-oriented design |
Which command compiles the Java source code file Welcome.java | javac Welcom.java |
Which statement is true (regard syntax) | Syntax errors are caught by the compiler. Logic errors have effects at execution time. |
Every Java application is composed of at least one: | public class declaration. |
What is the difference between a float and a double: | Double variables store numbers with larger magnitude and finer detail. |
Which of the following is not one of the three general types of computer languages? | Spoken languages |
Which of the following is not a Java keyword? | next |
What is the result value of c at the end of the following code segment: int c = 8; c++ ++c c %= 5; | 0 |
A(n) __________ enables a program to read data from the user. | Scanner |
Which of the following is not one of six logical units of a computer? | Printer |
Which of the following is not a Java primitive type? | real |
Attributes of a class are also known as: | Fields |
Which of the following statements about the break statement is false? | The break statement when executed in a while, for or do...while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. |
Which of the following will count down from 10 to 1 correctly(for loop)? | for ( int j = 10; j >= 1; j--) |
Consider the code segment below: if ( gender == 1 ) { if ( age >= 65 ) ++seniorFemales; } //end if The segment is equivalent to what? (using Logical operators) | if( gender == 1 && age >= 65) ++seniorFemales; |
Suppose the variable gender is MALE and age equals 60, how is the expression (gender == FEMALE) && (age >= 65) evaluated? | The condition ( gender == FEMALE ) is evaluated first and the evaluation stops immediately |
To exit out of a loop completely, and resume the flow of control at the next line in the method, use __________. | a break statement. |
Which of the following statements about the continuation statement is true? | A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement. |
The control variable of a counter-controlled loop should be declared as ______ to prevent errors. | int |
Which of the following statements about a do...while repetition statement is true? | The body of a do...while loop is always executed at least once. |
A well-designed method | performs a single, well-defined task |
Which statement creates a random value from the sequence 2, 5, 8, 11, and 14. Suppose randomNumbers is a Random object | 2 + 3 * randomNumbers.nextInt(5) |
To declare a method as static, place the keyword static before _________ in the method's declaration. | the return type. |
Suppose method1 is declared as void method1( int a, float b) Which of the following methods correctly overloads method 1? | void method1( float a, int b). |
In a class containing methods with the same name, the methods are distinguished by: | parameter number, types, and order of types. |
Consider the following Java statements: int x = 9; double 7 = 5.3; result = calculateValue(x , y); Are x and y parameters? | False |
the Java API consists of import declarations | False |
An overloaded method is one that: | has the same name as another method, but different parameters (by number or types or order of types) |
Stacks are known as ________ data structures. | LIFO |
Declaring main as _______ allows the JVM to invoke main without creating an instance of the class. | static |
A programmer must do what before using an array: | Declare then create the array |
Which method call converts the value in variable stringVariable to an integer? | Integer.parseInt( stringVariable ). |
What do the following statements do? double[] array; array = new double[ 14 ]; | Create a double array containing 14 elements. |
Which statement correctly passes the array items to method takeArray? Array items contains 10 elements. | takeArray( items ) |
In this question, assume a class, Book, has been defined. Which set of statements creates an array of Book objects? | Book[] books; books = new Book[ numberElements ]; |
Arrays are: | fixed-length entities. |
The preferred way to traverse a two-dimensional array is to use | two nested for statements |
Attempting to access an array element out of the bounds of an array, causes a(n) | ArrayIndexOutOfBoundsException. |
Consider the array: s[ 0 ] = 7 s[ 1 ] = 0 s[ 2 ] = -12 s[ 3 ] = 9 s[ 4 ] = 10 s[ 5 ] = 3 s[ 6 ] = 6 The value of s[ s[ 6 ] - s[ 5 ] ] is: | 9 |
Which of the following should usually be private? | Variables (or fields). |
Static class variables: | are shared by all objects of a class. |
When should a program explicitly use the this reference? | Accessing a field that is shadowed by a local variable. |
The import declaration import *; ________. | causes a compilation error. |
Instance variables declared final do not or cannot: | Be modified. |
Having a this reference allows: | All of the above. |
Which of the following is false? (Objects and finalize) | Objects are marked for garbage collection by method finalize. |
When no access modifier is specified for a method or variable, the method or variable: | Has package access. |
A class within a package must be declared public if | It will be used by classes that are not in the same package. |
Which superclass members are inherited by all subclasses of that superclass? | protected instance variables and methods |
Every class in Java, except ________, extends an existing class. | Object |
Superclass methods with this level of access cannot be called from subclasses. | private |
When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable? | The program compiles and runs because the instance variables are initialized to their default values |
Overriding a method differs from overloading a method because: | Overridden methods have the same signature. |
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? | super |
Using the protected keyword gives a member: | package access |
Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass’s method causes ________. | infinite recursion |
An advantage of inheritance is that: | Objects of a subclass can be treated like objects of their superclass. |
The default implementation of method clone of Object performs a ________. | shallow copy |
The preferred means of creating multithreaded Java applications is by implementing the ______ interface. An object of a class that implements the interface represents a task to perform. | Runnable |
The main method executes in the _____ thread of execution. | main |
When a _______ method or block is running on an object, the object is locked so no other such method can run on that object at the same time. | synchronized |
A new thread begins its life cycle by transitioning to the __________ state. | new |
What should be put in a try block? | The try block should contain statements that may throw an exception |
Can ExecutorService be run in a separate thread? | No |
In the catch block below, what is arithmeticException? catch ( ArithmeticException arithmeticException ) { System.err.printf( arithmeticException ); } // end catch | The name of catch block’s exception parameter |
All exception classes inherit, either directly or indirectly, from: | class Throwable |
To catch an exception, the code that might throw the exception must be enclosed in a | try block |
An uncaught exception: | is an exception that occurs for which there are no matching catch clauses. |
The classes and interfaces which comprise the collections framework are members of package ________. | java.util |
(True/False): A list cannot duplicate elements. | True |
Which statement best describes the relationship between superclass and subclass types? | A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable. |
Which superclass members are inherited by all subclasses of that superclass? | protected instance variables and methods |
Every class in Java, except _______, extends an existing class | Object |
Superclass methods with this level of access cannot be called from subclasses | private |
When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable. | The program compiles and runs because the instance variables are initialized to their default values |
Overriding a method differs from overloading a method because: | Overriden methods have the same signature. |
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? | super |
using the protected keyword give s member | private access |
Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass’s method causes ________. | infinite recursion |
An advantage of inheritance is that: | Objects of a subclass can be treated be like objects of their superclass. |
Which of the following should usually be private? | Variables (or fields). |
A package is | All things! |
When should a program explicitly use the " this " reference? | Accessing a field that is shadowed by a local variable |
Instance variables declared final do not or cannot: | Be modified |
(True/False): Objects are marked for garbage collection by method finalize. | False. |
When no access modifier is specified for a method or variable, the method or variable: | Has packaged access. |
Which method prints an new line or /n? | println |
What is the scope of a parameter declaration | the body of the method in which the declaration appears. |
What is the scope of a local-variable declaration | is from the point at which the declaration appears to the end of the block. |
How are overloaded methods distinguished? | by their signatures, combinations of the method’s names and the number, types and order of the parameters, but not their return types. |
A class can have references to objects of other classes as members. This is called composition and is sometimes referred to as a ______ relationship | has-a |