1/125
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which statement best reflects a property or characteristic of a constructor?
has the same name as the class
Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?
String prefix = listing.substring(0,5);
Do constructors have a return type?
false
Static member functions can only access member variables that are also static.
True
A constructor is a method that __________. Choose the best answer.
performs creation, initialization or setup of an object
A constructor is invoked to create an object using the ________ operator.
new
Get methods are also called ___________ type methods.
accessor
How are instance member and static member variables different?
only one instance of a static variable exists in memory
When does a static member variable come into existence in memory?
before any instances of its class
Set methods are also called ___________ type methods.
mutator
Which method returns the number of characters stored in StringBuilder?
length()
Class abstraction separates class implementation from the use of the class.
true
When a method has the same name as another method but different parameters, it is referred to as ______________________
overloaded
Given the declaration Circle x = new Circle(), which of the following statement is most accurate.
x contains a reference to a Circle object
For the following String:
String str = "ABcdeFGH";
What will be returned from the following statements?
Character.toUpperCase(str.charAt(3));
Character.toUpperCase(str.charAt(5));
DE
Which of the following method headers is most likely a header for a mutator method?
public void setAge(int newAge)
Converting a primitive or class in Java into other type is called ______________.
casting
A super class can be derived from another class.
true
Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?
String prefix = listing.substring(0,5);
Another term for an object of a class is a(n) __________.
instance
Which operator is used to access a data field or invoke a method from an object?
the dot operator
This keyword is means that a variable is not able to be modified once it is initialized.
final
Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?
String prefix = listing.substring(0,5);
Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?
x contains a reference to an array and each element in the array can hold a reference to a Circle object.
Get methods are also called ___________ type methods.
accessor
A method that has multiple definitions distinguished by the parameter number or type is an __________________ method.
overloaded
Which access specifier is most appropriate to implement encapsulation?
private
instances of wrapper classes are immutable.
true
A constructor with only one parameter is the "default" constructor.
false
Which method returns the number of characters stored in StringBuilder?
length()
A ___________ variable represents information or data shared by all objects of the class.
static
The "this" pointer is passed to a static member function.
false
Converting a primitive or class in Java into other type is called ______________.
casting
Suppose that Horse is a subclass of Animal, and neither class is abstract. Which of the following is an invalid declaration and initialization?
Horse h = new Animal();
Which class can you use to write data into a text file?
PrintWriter
To catch an exception, the code that might have an error must be enclosed in a ________________ block.
try
"try-with-resources" syntax is used to ___________________.
automatically close the files used in the program.
A(n) _____________________ is an object that defines an erroneous situation from which the program usually cannot recover.
error
A finally clause is always required in a try-catch block.
false
To handle an exception that has been thrown, a program must have a(n) ____________________
try/catch block
What does the following statement do?
Scanner scanner = new Scanner(Paths.get("test.txt"));
Opens a text file for input.
All exception classes inherit, either directly or indirectly, from ________.
class Throwable.
If the data.dat file already exists, what will happen when the following statement is executed?
FileWriter fwriter = new FileWriter("data.dat");
The file will be erased and replaced with the new file
Files that are open for output from a program must be explicitly closed in the program.
true
Which of the following exceptions is a checked exception?
IOException.
Which method can be used to read a whole line from the file?
nextLine
In a try/catch construct, after the catch statement is executed __________.
the program resumes at the statement that immediately follows the try/catch construct
A(n) ____________________ is used to specify how certain exceptions should be handled.
catch block
An uncaught exception ________.
is an exception that occurs for which there are no matching catch clauses.
What is the java root class for exceptions?
java.lang.Throwable
Which class contains the method for checking whether a file exists?
File
Which of the following statements regarding abstract classes and methods is FALSE?
A data field can be declared abstract.
Which keyword is used when requiring an interface for a class?
implements
Which of the following statements is correct?
An abstract class may contains constructors.
Which statement best reflects the definition of a Java interface?
a collection of abstract methods and constants
Which of the following statements regarding abstract methods is false?
A data field can be declared abstract.
A subclass can implement multiple interfaces.
true
Class abstraction separates class implementation from the use of the class.
true
Which of the following statements regarding abstract methods is FALSE?
An abstract class can have instances created using the constructor of the abstract class.
What is an abstract method?
A method which is not implemented.
If Person is an interface. Then it is possible to create an object by instantiating the Person interface.
false
Of the classes below, the one that is most likely to be declared abstract is _________________.
a) dog
b) cat
c) animal
d) horse
animal
Which of these access specifiers is most appropriate to use for an interface?
public
How many base cases must a recursive method have?
at least one
What is wrong with the following recursive method that computes the sum of all of the odd positive integers less than or equal to n?
public int sumOfOdds(int n)
{
if(n%2 == 0)
return sumOfOdds(n-1);
else
return n + sumOfOdds(n-2);
}
a) there are two base cases
b) adds both even and odd
c) no base case
d) recursive values don't decrement correctly
no base case
All mathematical problems are designed to be more efficient using recursive solutions.
false
Which type of recursion is more difficult to debug?
indirect
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
true
Without a base case, a recursive method will call itself only once and stop.
false
____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method.
a) upward, downward
b) downward, upward
c) direct, indirect
d) indirect, direct
direct, indirect
Recursive solutions are always more efficient than iterative solutions
false
In the following code that uses recursion to find the greatest common divisor of a number, what is the base case?
public static int gcd(int x, int y)
{
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
a) gcd(int x, int y)
b) if (x % y == 0)
return y;
c) else
return gcd(y, x % y);
d) cannot tell from this code
if (x % y == 0)
What is one of the benefits of recursion?
shorter code
A _____________________ method is one that calls itself.
recursive
25 % 5 is ______?
0
Which of the following is the correct statement to return JAVA?
a) String.toUpperCase("Java")
b) toUpperCase("Java")
c) "Java".toUpperCase()
d) "Java".toUpperCase("Java")
"Java".toUpperCase()
What is the index variable for the element at the second row and first column in array a?
a) a[0][1]
b) a[2][1]
c) a[1][0]
d) a[1][1]
a[1][0]
What is the exact output of the following code?
public class MyClass {
public static void main(String args[]) {
float num = 7.3f;
System.out.print("num");
System.out.print(num);
}
}
a) 7.3
b) num7.3f
c) num7.3
d) 7.37.3
num7.3
What is displayed in the following code?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x-- + x;
System.out.println("y is " + y);
}
}
a) y is 1
b) y is 4
c) y is 2
d) y is 3
y is 1
When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as _________.
pass by value
Suppose x is 1. What is x after x += 1?
2
The __________ method returns a raised to the power of b.
a) Math.pow(b, a)
b) Math.pow(a, b)
c) Math.power(a, b)
d) Math.exponent(a, b)
Math.pow(a, b)
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count
11
"abc".compareTo("aba") returns ___________.
a) -1
b) 2
c) -1
d) 1
2
How many elements are array matrix (int[][] matrix = new int[2][5])?
a) 20
b) 10
c) 25
d) 14
10
Which loop statement will execute the code before the loop condition is tested?
a) for each
b) for
c) while
d) do-while
do-while
An _____ object cannot be modified
immutable
the _____ clause is always executed regardless of wether an exception occurred or not
finally
the keyword _____ can be used to refer to its calling object. It can also be used inside a constructor ti invoke another constructor of the same class
this
_____ is a special form of association between classes that represents an ownership between objects
aggregation
the separation of class implementation from the use of a class is called class ______
abstraction
_____ means that a variable of a supertype can refer to a subtype object
polymorphism
a _____ is a template for objects
class
the keyword _____ can be used to invoke the superclass's methods and constructors
super
_____ means to define multiple methods with the same name but different signatures
overloading
_____ means ti provide a new implementation for a method in the subclass
overriding
_____ enables a program to deal with exceptional situations in an orderly manner
exception handling
using _____ you can define a general class and extend it into a more specialized class
inheritance
when an object reference can be typecast into another object reference it is called _____
casting
Converting a primitive value to a wrapper object is called _____.
boxing