What would be the best description of polymorphism.
QUESTION 2
What would be the best description of polymorphism.
A java object that can be attached to or refer to more than one class. | ||
An object that refers to its parent. | ||
An object that refers to itself. | ||
Downcasting. |
5 points
Save your time - order a paper!
Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines
Order Paper NowQUESTION 3
Java Swing classes allow for text components to be read only via what method?
setReadOnly() | ||
setEditable() | ||
setEditOnly() | ||
setTextReadOnly() |
5 points
QUESTION 4
A constructor is a special kind of method within a class having the following features:
1) the name of the method is the same as the class name
2) it does not have any return type not even void
3) like other methods, constructors can also be overloaded
Choose the correct assumption(s) from the listing above.
Only assumption 1 is correct. | ||
Assumptions 1 & 2 are correct | ||
None are correct. | ||
All assumptions are good. |
5 points
QUESTION 5
When creating a jar file (for executing a java program for a user) you can only choose one file in your package that has main().
True
False
5 points
QUESTION 6
Which of the following is true about protected access?
Protected members cannot be accessed by methods in any other classes. | ||
Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. | ||
Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. | ||
Protected members are actually named constants. |
5 points
QUESTION 7
In the following code, System.out.println(num), is an example of ________.
double num = 5.4;
System.out.println(num);
num = 0.0;
A value-returning method | ||
A local variable | ||
A complex method | ||
A void method |
5 points
QUESTION 8
A column in one table that references a primary key in another table is known as what?
referential key | ||
secondary key | ||
foreign key | ||
meta data |
5 points
QUESTION 9
Which is not a solid example of encapsulation?
A Car class having a has-a relation with class Parts | ||
Taking for granted a wikipedia definition | ||
A washing machine and its use of a power Button | ||
java.util.Hashtable |
5 points
QUESTION 10
Given the depiction below, the relation of Song to Artist is one to one.
True
False
5 points
QUESTION 11
To convert the double variable, d = 543.98, to a string, use the following statement.
String str = Double.toString(d); | ||
String str = d.Double.toString(str); | ||
String str = double.toString(d); | ||
String str = double(d); |
5 points
QUESTION 12
An abstract class is not instantiated, but serves as a superclass for other classes.
True
False
5 points
QUESTION 13
For an optimal OOD design it is best to have
classes that are tightly coupled with high cohesion | ||
classes that are loosely coupled with low cohesion | ||
classes that are tightly coupled with low cohesion | ||
classes that are loosely coupled with high cohesion |
5 points
QUESTION 14
A search algorithm
Arranges elements in ascending order | ||
Arranges elements in descending order | ||
Is a way to locate a specific item in a larger collection of data | ||
Is rarely used with arrays |
5 points
QUESTION 15
In an interface all methods have
private access | ||
public access | ||
protected access | ||
packaged access |
5 points
QUESTION 16
Given the generic method below, what data types can be passed in?
public static
void displayArray(E[ ] array) {
for (E element : array)
::
}
any data type | ||
any reference type | ||
any data type that is a sub class of Number | ||
any type that a super class of Number |
5 points
QUESTION 17
The following statement creates an ArrayList object. What is the purpose of the notation?
ArrayList arr = new ArrayList<>();
It specifies that everything stored in the ArrayList object will be converted to a String | ||
It specifies that only String objects may be stored in the ArrayList object | ||
Nothing as the statement is invalid. | ||
It specifies that the get method will return only String objects |
5 points
QUESTION 18
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
True
False
5 points
QUESTION 19
In a class hierarchy
the more general classes are toward the left of the tree and the more specialized are toward the right | ||
the more general classes are toward the bottom of the tree and the more specialized are toward the top | ||
the more general classes are toward the top of the tree and the more specialized are toward the bottom | ||
the more general classes are toward the right of the tree and the more specialized are toward the left |
5 points
QUESTION 20
Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B?
if (chr < ‘B’) | ||
if (chr != “B”) | ||
if (chr != ‘B’) | ||
if (chr > ‘B’) |
5 points
QUESTION 21
The three major categories of Java collections are
tree sets, list sets, and hash maps | ||
lists, sets, and maps | ||
hash lists, hash tables, and sets | ||
sets, collections, and maps |
5 points
QUESTION 22
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement
str.uppercase(); | ||
str[0].toUpperCase(); | ||
str.toUpperCase(); | ||
str[0].upperCase(); |
5 points
QUESTION 23
What would be the results of the following code?
final int SIZE = 25;
int[] array1 = new int[SIZE];
… // Code that will put values in array1
int value = 0;
for (int a = 0; a <= array1.length; a++)
{
value += array1[a];
}
value contains the lowest value in array1 | ||
value contains the sum of all the values in array1 | ||
value contains the highest value in array1 | ||
This would cause the program to crash. |
5 points
QUESTION 24
What is the value of str after the following code has been executed?
String str;
String sourceStr = “Hey diddle, diddle, the cat and the fiddle”;
str = sourceStr.substring(12,17);
Iddle | ||
diddl | ||
diddle | ||
, didd |
5 points
QUESTION 25
If a subclass constructor does not explicitly call a superclass constructor,
The superclass fields will be set to the default values for their data types | ||
It must include the code necessary to initialize the superclass fields | ||
Java will automatically call the superclass’s default constructor just before the code in the subclass’s constructor executes | ||
Java will automatically call the superclass’s default constructor immediately after the code in the subclass’s constructor executes |
5 points
QUESTION 26
What term refers to data that describes other data?
meta data | ||
pseudo-data | ||
micro data | ||
abstract data |
5 points
QUESTION 27
If a class contains an abstract method,
The method must be overridden in subclasses | ||
You cannot create an instance of the class | ||
The method will have only a header, but not a body, and end with a semicolon | ||
All of the above |
5 points
QUESTION 28
In the following code, System.out.println(num), is an example of ________.
double num = 5.4;
System.out.println(num);
num = 0.0;
A value-returning method | ||
A local variable | ||
A complex method | ||
A void method |
5 points
QUESTION 29
In the realm of JDBC use of PreparedStatements help prevent what?
SQL Injection | ||
increased threads | ||
does not prevent anything, just executes insert statements like JDBC statements do | ||
execution of stored procedures |
5 points
QUESTION 30
If a subclass constructor does not explicitly call a superclass constructor,
It must include the code necessary to initialize the superclass fields | ||
The superclass fields will be set to the default values for their data types | ||
Java will automatically call the superclass’s default constructor just before the code in the subclass’s constructor executes | ||
Java will automatically call the superclass’s default constructor immediately after the code in the subclass’s constructor executes |
5 points
QUESTION 31
Given:
public class MyPancake implements Pancake {
public static void main(String[] args) {
List x = new ArrayList();
x.add(“3”); x.add(“7”); x.add(“5”);
List y = new MyPancake().doStuff(x);
y.add(“1”);
System.out.println(x);
}
List doStuff(List z) {
z.add(“9”);
return z;
}
}
interface Pancake {
List doStuff(List s);
}
What is the most likely result?
An exception is thrown at runtime | ||
Compilation fails | ||
[3, 7, 5, 9, 1] | ||
[3, 7, 5] | ||
[3, 7, 5, 9] |
5 points
QUESTION 32
Assume q passed into the function below is: q={10,9,8,7,6,5,4,3,2,1}
What would be the resulting stack (st) at the line below with the comment labeled //1.____
public Queue interChanger(Queue q){
Stack st = new Stack();
int size = q.size()/2;
for(int i = 1; i <= size; i++){
st.push(q.remove()); //1. ____________
}
while(!st.isEmpty()){
q.add(st.pop()); //2. ____________
}
for(int i = 1; i <= size; i++){
q.add(q.remove()); //3. ____________
}
for(int i = 1; i <= size; i++){
st.push(q.remove()); //4. ____________
}
while(!st.isEmpty()){
q.add(st.pop());
q.add(q.remove()); //5. ____________
}
return q;
}
12345 | ||
54321 | ||
678910 | ||
109876 |
5 points
QUESTION 33
A major problem when classes are tightly coupled may be when what occurs?
When functions using local variables change the variables unexpectedly | ||
When global variables that are in use and cause havoc perhaps upon any changes to them | ||
When the constructor of a class no longer can rely on changes to the class variablesupon instantiation being unchanged | ||
Tightly coupled classes are actually very beneficial and recommended to be coded in that fashion. |
5 points
QUESTION 34
As a programmer we should try to
balance between tightly and loosely coupled classes. | ||
minimize the use of coupling relations of classes | ||
maximize the use of any coupling relations of classes | ||
only allow tight coupling when changes need to be made to classes for maintenance purposes. |
5 points
QUESTION 35
Given the Regex expression:
^[a-z0-9_-]{3,15}
and a string to compare against the expression such as
tom-thumbtomthumb
a match would be
tom | ||
tom- | ||
tom-thumbtomthu | ||
tom-thumbtomthumb |
5 points
QUESTION 36
What would be the results of executing the following code?
StringBuilder str = new StringBuilder(12);
str.append(“The cow”);
str.append(” jumped over the “);
str.append(“moon.”);
variable str would equal “The cow jump” | ||
variable str would equal “The cow jumped over the” | ||
variable str would equal “The cow jumped over the moon.” | ||
The program would crash. |
5 points
QUESTION 37
Given the ages for object creations for class AgeGroups as 33,22,44,55 respectively, what would the following Comparator declaration return for each age outcome order?
Collections.sort(listDevs, new Comparator() {
@Override
public int compare(AgeGroups o1, AgeGroups o2) {
return -o1.getAge() ;
}
});
33,22,44,55 | ||
55,44,22,33 | ||
22,33,44,55 | ||
order would be random |
5 points
QUESTION 38
An abstract class cannot be instantiated primarily because
any of the class attributes cannot be modified | ||
subclasses should only be allowed to implement the desired behaviors associated with the abstract class its inheriting from | ||
methods may choose to be overriding any behaviors that may be declared abstract by the inherited abstract class | ||
too much memory would be allocated for both the super (abstract) class and any of its decendents. |
5 points
QUESTION 39
In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file:
double totalIncome = 0.0;
while (inputFile.hasNext())
{
try
{
totalIncome += inputFile.nextDouble();
}
catch(InputMismatchException e)
{
System.out.println(“Non-numeric data encountered ” +
“in the file.”);
inputFile.nextLine();
}
finally
{
totalIncome = 35.5;
}
}
What will be the value of totalIncome after the following values are read from the file?
2.5
8.5
3.0
5.5
abc
1.0
0.0 | ||
19.5 | ||
75.0 | ||
35.5 |
5 points
QUESTION 40
In an interface all methods have
private access | ||
public access | ||
packaged access | ||
protected access |
Artist Performs Song