Professional Documents
Culture Documents
Java Fundamentals FinalTest Exam
Java Fundamentals FinalTest Exam
Section 4
(Answer all questions in this section)
True
False (*)
Correct
True or false?
True (*)
False
Correct
Cayrbniz
CayrbnizCayrbniz
yr (*)
ay
ArrayIndexOutofBoundsException is thrown
Correct
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Correct
s1 == s2
s1 = s2
s3 == s1 (*)
s1.equals(s2)
s3.equals(s1)
Correct
Section 4
(Answer all questions in this section)
Correct
Correct
2bad (*)
zero
theLastValueButONe
year2000
Correct
9. Which of the following is the name of a Java primitive data type?
Mark for
Review
(1) Points
Object
Rectangle
double (*)
String
Correct
10.A workspace can not have more than one stored projects. True or
Mark for
false?
Review
(1) Points
True
False (*)
Correct
Section 4
(Answer all questions in this section)
11.Multiple windows are used when more than one file is open in the
Mark for
edit area. True or False?
Review
(1) Points
True
False (*)
// (*)
/*
*/
/*/
Correct
Collect
Compile (*)
Package
Assemble
Correct
Correct
Section 5
(Answer all questions in this section)
15.switch statements work on all input types including, but not limited
Mark for
to, int, char, and String. True or false?
Review
(1) Points
True
False (*)
Correct
Section 5
(Answer all questions in this section)
16.How would you use the ternary operator to rewrite this if statement?
Mark for
Review
if (gender == "female") System.out.print("Ms.");
(1) Points
else
System.out.print("Mr.");
True (*)
False
18.In the code fragment below, the syntax for the for loop's initialization
Mark for
is correct. True or false?
Review
(1) Points
public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))<br> {System.out.Println ("i: "+i); }
}
}
True
False (*)
19.When the for loop condition statement is met the construct is exited.
Mark for
True or false?
Review
(1) Points
True
False (*)
Correct
It is a post-test loop.
It is a modified while loop that allows the program to run
through the loop once before testing the boolean condition.
It continues looping until the condition becomes false.
All of the above. (*)
Correct
Section 6
(Answer all questions in this section)
21Which of the following statements add all of the elements of the one
Mark for
. dimensional array prices, and then prints the sum to the screen?
Review
(1) Points
int total = 0;
for(int i = 0; i
total+=prices[i];
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(total); (*)
int total = 0;
for(int i = 1; i
total = total+prices[i];
System.out.println(prices);
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(prices);
Correct
22What is the output of the following segment of code if the command line
Mark for
. arguments are "a b c d e f g"?
Review
(1) Points
f
e (*)
c
d
This code doesn't compile.
321123
642
642246 (*)
312213
This code doesn't compile.
Correct
True (*)
False
Correct
25What is wrong with this code?
Mark for
.
Review
(1) Points
It is missing a semicolon.
It does not compile. (*)
It gives you an out of bounds exception.
There is nothing wrong with this code.
Correct
Section 6
(Answer all questions in this section)
True (*)
False
Correct
n
n^2
lg(n) (*)
n*lg(n)
Correct
28.Bubble Sort is a sorting algorithm that involves swapping the
Mark for
smallest value into the first index, finding the next smallest value and
Review
swapping it into the next index and so on until the array is sorted.
(1) Points
True or false?
True
False (*)
Correct
Correct
Section 7
(Answer all questions in this section)
Correct
Section 7
(Answer all questions in this section)
Methods
Parameters
Overload constructors
Access modifiers (*)
protected (*)
public (*)
secured
default (no access modifier) (*)
private (*)
35.What is Polymorphism?
Mark for
Review
(1) Points
Correct
Section 7
(Answer all questions in this section)
Correct
37.Abstract classes cannot implement interfaces. True or false?
Mark for
Review
(1) Points
True
False (*)
Correct
Forward
Backward (*)
Both forward and backward
None of the above
Correct
39.There is only one copy a static class variable in the JVM. True or
Mark for
false?
Review
(1) Points
True (*)
False
Correct
True
False (*)
Correct
Section 7
(Answer all questions in this section)
4In Java, an instance field referenced using the this keyword generates a
Mark for
1.compilation error. True or false?
Review
(1) Points
True
False (*)
Correct
True (*)
False
Correct
4A constructor must have the same name as the class where it is declared.
Mark for
3.True or false?
Review
(1) Points
True (*)
False
Correct
4Identify the driver class that correctly initializes employees Jane and
Mark for
4.Brandon. The Employee class is below.
Review
(1) Points
public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}
public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane", 48, 35.00);
Employee Brandon = new Employee("Brandon", 36, 20.00);
}
} (*)
public class driver_class {
public static void main(String[] args) {
Employee("Jane", 48, 35.00);
Employee("Brandon", 36, 20.00);
}
}
public class driver_class {
public Employee{
Jane = new Employee("Jane", 48, 35.00);
Brandon = new Employee("Brandon", 36, 20.00);
}
}
public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}
True
False (*)
Correct
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
Correct
(*)
50.What is encapsulation?
Mark for
Review
(1) Points
A keyword that allows or restricts access to data and methods.
A programming philosophy that promotes simpler, more
efficient coding by using exiting code for new applications.
A structure that categorizes and organizes relationships among
ideas, concepts of things with the most general at the top and the
most specific at the bottom.
A programming philosophy that promotes protecting data and
hiding implementation in order to preserve the integrity of data
and methods. (*)