QUESTION 30 If a subclass constructor does not explicitly call a superclass cons
ID: 3831203 • Letter: Q
Question
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<String> x = new ArrayList<String>();
x.add("3"); x.add("7"); x.add("5");
List<String> y = new MyPancake().doStuff(x);
y.add("1");
System.out.println(x);
}
List<String> doStuff(List<String> z) {
z.add("9");
return z;
}
}
interface Pancake {
List<String> doStuff(List<String> 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<Integer> st = new Stack<Integer>();
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 variables
upon 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<AgeGroups>() {
@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
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
Explanation / Answer
Question - 40
In interface all methods have public.
Question 39:
the value is 35.5
Question 38
subclasses is only be allowed to implement the desired behaviour associated with the Abstract class it inheritence from
Question 37:
33,22,44,55
Question 36
The cow jumped over the moon is the value of the variable
Question 35
the character a to z and to 9 and _ that may repeat 3 to 15 times tom
QUestion 34
Should maintain a balance between tightly and loosely coupled classes
Question 33
When the global variables that are in use and causes havac perhaps any changes to them
Question 32
109876
Question 31
[3, 7, 5, 9,1 ]
Question 30
super class will set to default values.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.