Professional Documents
Culture Documents
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 4
(Answer all questions in this section)
1. In Eclipse, when you run a Java Application, where may the results display?
Mark for Review
(1) Points
Editor Window
Console View (*)
Debug View
Task List
None of the above
Correct
2. What are the Eclipse Editor Area and Views used for? Mark for Review (1)
Points
(Choose all correct answers)
To modify elements. (*)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
Correct
3. A combination of views and editors are referred to as _______________. Mark
for Review
(1) Points
A workspace
A physical location
A perspective (*)
All of the above
Correct
Example A (*)
Example B
Correct
9. What are Java's simple types? Mark for Review (1) Points
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short
Correct
10. Select the declaration and initialization statement that will hold the letter J.
Mark for Review
(1) Points
int letter='J';
float letter='J';
String letter='J';
char letter='J'; (*)
Correct
Previous Page 2 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 4
(Answer all questions in this section)
11. Which of the following are relational operators in Java? Mark for Review
(1) Points
(Choose all correct answers)
< (*)
<= (*)
=
!= (*)
All of the above.
Correct
12. What is the output of the following lines of code?
int j=6,k=4,m=12,result;
result=j/m*k;
System.out.println(result); Mark for Review (1) Points
2
0 (*)
48
24
Correct
13. Which of the following is the name of a Java primitive data type? Mark for
Review
(1) Points
Object
Rectangle
double (*)
String
Correct
14. The three logic operators in Java are: Mark for Review (1) Points
&&, ||, ! (*)
!=,=,==
&&,!=,=
&,|,=
Correct
15. The six relational operators in Java are: Mark for Review (1) Points
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
Correct
Previous Page 3 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 5
16. All of the following are essential to initializing a FOR loop, except which
one? Mark for Review
(1) Points
Initializing the iterator(i).
25. The following code creates an Object of type Horse. True or false?
Whale a=new Whale(); Mark for Review (1) Points
True
False (*)
Correct
Previous Page 5 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 5
26. The following code is a good example of using the this reference. True or
false?
456789
777777 (*)
555555
987654
This code doesn't compile.
Correct
29. Which of the following statements is not a valid array declaration? Mark
for Review
(1) Points
int number[];
float []averages;
double marks[5];
counter int[]; (*)
Incorrect. Refer to Section 6 Lesson 1.
30. What is the output of the following segment of code?
int array[][] = {{1,2,3},{3,2,1}};
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
System.out.print(2*array[1][1]); Mark for Review (1) Points
444444 (*)
123321
246642
222222
This code doesn't compile.
Correct
Previous Page 6 of 10 Next Summary
False (*)
Correct
34. The == operator can be used to compare two String objects. The result is
always true if the two strings are have the exact same characters in each
position of the String. True or false? Mark for Review (1) Points
True
False (*)
Correct
35. Which of the following could be a reason to throw an exception? Mark for
Review
(1) Points
To eliminate exceptions from disrupting your program. (*)
You have a fatal error in your program.
You have encountered a Stack Overflow Error.
To make the user interface harder to navigate.
Correct
Previous Page 7 of 10 Next Summary
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 6
36. Which of the following correctly matches the symbol with its function?
Mark for Review
(1) Points
== (two equal signs) compares values of primitive types such as int or char.
(*)
= (single equals sign) compares the value of primitive types such as int or
char.
Correct
37. If an exception is thrown by a method, where can the catch for the
exception be? Mark for Review
(1) Points
The catch can be in the method that threw the exception or in any other
method that called the method that threw the exception. (*)
38. Suppose you are writing a program where the user is prompted to the give
coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the
princess is not found at those coordinates, the user is given a clue that helps
them guess coordinates closer to the princess. The user is allowed to enter their
new guess of where the princess is.
Assume your program does not take into consideration the possibility that the
user may enter coordinates outside of the castle where the princess could not
be. What would be the result of the user entering coordinates outside of the
castle? How could this be handled in your code? Mark for Review
(1) Points
An exception would occur but could not be handled inside your code. The user
would have to restart the program and enter proper coordinates.
Section 7
(Answer all questions in this section)
39. An access modifier is a keyword that allows subclasses to access methods,
data, and constructors from their parent class. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 3.
40. Which of the following is the correct way to call an overriden method
needOil() of a super class Robot in a subclass SqueakyRobot? Mark for Review
(1) Points
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
Incorrect. Refer to Section 7 Lesson 3.
Previous Page 8 of 10 Next Summary
41. What is the Java Applet? Mark for Review (1) Points
(Choose all correct answers)
It is the virtual machine that translates Java code into a representation that
the computer can understand.
A web-based Java program that is embedded into a web browser. (*)
A graphic visual included in Java. (*)
There is no such thing as a Java Applet.
Incorrect. Refer to Section 7 Lesson 3.
42. Which segment of code represents a correct way to define a variable
argument method? Mark for Review (1) Points
String easyArray(String... elems) {//code} (*)
String easyArray(...String elems) {//code}
String... easyArray(String elems) {//code}
Integer easyArray... (int elems) {//code}
Correct
43. Which of the following is the correct way to code a method with a return
type an object Automobile? Mark for Review (1) Points
Automobile upgrade(String carA){
carA="Turbo";
return carA;}
44. Choose the correct implementation of a public access modifier for the
method divide. Mark for Review (1) Points
divide(int a, int b, public) {return a/b;}
public divide(int a, int b) {return a/b;} (*)
divide(int a, int b) {public return a/b;}
divide(public int a, public int b) {return a/b;}
Correct
45. Static methods can read instance variables. True or false? Mark for Review
(1) Points
True
False (*)
Correct
Previous Page 9 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 7 (Answer all questions in this section)
46. Static methods can write to class variables. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 2.
47. A static variable is always publicly available. True or false? Mark for
Review (1) Points
True
False (*)
Correct
48. Abstract classes cannot implement interfaces. True or false? Mark for
Review (1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 4.
49. If Oak extends Tree, it is possible to declare an object such that
Tree grandfatherT = new Oak();
True or false? Mark for Review (1) Points
True (*)
False
Correct
50. Abstract class cannot extend another abstract class. True or false? Mark
for Review
(1) Points
True
False (*)
Correct
Previous Page 10 of 10 Summary
Section 4
(Answer all questions in this section)
1. The six relational operators in Java are: Mark for Review
(1) Points
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
Correct
2. The three logic operators in Java are: Mark for Review
(1) Points
&&, ||, ! (*)
!=,=,==
&&,!=,=
&,|,=
Correct
3. What does the following program output?
4. Which line of Java code will assign the square root of 11 to a? Mark for
Review
(1) Points
double a=11^(1/2);
double a=sqrt(11);
int a=Math.sqrt(11);
double a=Math.sqrt*11;
double a=Math.sqrt(11); (*)
Correct
5. What two values can a boolean variable have? Mark for Review (1) Points
Numbers and characters
True and false (*)
Relational and logic operators
Arithmetic and logic operators
Integers and floating point types
Correct
Page 1 of 10 Next Summary
Test: Java Fundamentals Final Exam
Section 4
(Answer all questions in this section)
6. Given the following declaration, which line of Java code properly casts one
type into another without data loss?
int i=3,j=4; double y=2.54; Mark for Review (1) Points
int x=(double)2.54;
double x=i/j;
double x=(double)(i/j);
double x= double i/j;
10. Which of the two diagrams below illustrate the general form of a Java
program?
Debug View
Task List
None of the above
Correct
15. What are the Eclipse Editor Area and Views used for? Mark for Review (1)
Points
(Choose all correct answers)
To modify elements. (*)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
Correct
Previous Page 3 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 5
16. Which of the following best describes a WHILE loop? Mark for Review (1)
Points
A loop that contains a segment of code that is executed before the conditional
statement is tested.
A loop that executes the code at least one time even if the conditional
statement is false.
A loop that is executed repeatedly until the conditional statement is false. (*)
A loop that contains a counter in parenthesis with the conditional statement.
Correct
17. Switch statements work on all input types including, but not limited to, int,
char, and String. True or false? Mark for Review (1) Points
True
False (*)
Correct
18. Why are loops useful? Mark for Review (1) Points
19. Which of the following correctly matches the switch statement keyword to
its function? Mark for Review (1) Points
(Choose all correct answers)
switch: tells the compiler the value to compare the input against
default: signals what code to execute if the input does not match any of the
cases (*)
case: signals what code is executed if the user input matches the specified
element (*)
if: records the user's input and sends it to the case statements to find a
possible match
switch: identifies what element will be compared to the element of the case
statements to find a possible match (*)
Correct
20. What is wrong with the following class declaration?
class Account{ ;
privateint number;
privateString name;;
Account;;
}
Mark for Review (1) Points
Classes cannot include strings.
Classes cannot include mixed data types.
The constructor method has no definition. (*)
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 5
21. Which of the following may be part of a class definition? Mark for Review
(1) Points
Instance variables
Instance methods
Constructors
All of the above. (*)
None of the above.
Incorrect. Refer to Section 5 Lesson 2.
22. The constructor method must always have at least one parameter. True or
false? Mark for Review (1) Points
True
False (*)
Correct
23. A constructor must have the same name as the class it is declared within.
True or false? Mark for Review (1) Points
True (*)
False
Correct
24. The basic unit of encapsulation in Java is the primitive data type. True or
false? Mark for Review (1) Points
True
False (*)
Correct
25. In Java, an instance field referenced using the this keyword generates a
compilation error. True or false? Mark for Review (1) Points
True
False (*)
Correct
System.out.println(prices);
c)
int total
d)
int total=0;
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 6
31. Consider the following code snippet.
34. The == operator tests if two String references are pointing to the same
String object. True or false? Mark for Review (1) Points
True (*)
False
Correct
35. What does it mean to catch an exception? Mark for Review (1) Points
It means you have fixed the error.
It means to throw it.
It means to handle it. (*)
It means there was never an exception in your code.
Correct
Previous Page 7 of 10 Next Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 6
36. A logic error occurs if an unintentional semicolon is placed at the end of a
loop initiation because the interpreter reads this as the only line inside the loop,
a line that does nothing. Everything that follows the semicolon is interpreted as
code outside of the loop. True or false? Mark for Review (1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 3.
37. Which of the following correctly matches the symbol with its function?
Mark for Review
(1) Points
(Choose all correct answers)
== (two equal signs) compares values of primitive types such as int or char.
(*)
== (two equal signs) compares the values of non-primitive objects.
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Section 7
(Answer all questions in this section)
41. What is true about the Object class? Mark for Review (1) Points
(Choose all correct answers)
It is the highest superclass. (*)
It extends other classes.
Its methods can be overridden in subclasses. (*)
Its methods can be overloaded in subclasses. (*)
Correct
42. An access modifier is a keyword that allows subclasses to access methods,
data, and constructors from their parent class. True or false? Mark for Review
(1) Points
True (*)
False
Correct
43. Which of the following correctly describes an Is-A relationship? Mark for
Review
(1) Points
A helpful term used to conceptualize the relationships among nodes or leaves
in an inheritance hierarchy. (*)
Having more than one constructor with the same name but different
arguments. (*)
Having more than one constructor with different names and the same
arguments.
A variable argument method that returns an array.
A type of access specifier that only allows access from inside the same class.
Correct
47. Which of the following is the correct way to code a method with a return
type an object Automobile? Mark for Review (1) Points
a) Automobile upgrade(String carA){
carA="Turbo";
return carA;}
b)
carA.setTurbo("yes");
return carA;} (*)
c)
carA="Turbo";
return carA;}
d)
carA.setTurbo("yes");
return carA;}
None of the above. It is not possible to return an object.
Correct
48. Static methods can't act like "setter" methods. True or false? Mark for
Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 2.
49. Static classes are designed as thread safe class instances. True or false?
Mark for Review
(1) Points
True
False (*)
Correct
50. Static methods can read instance variables. True or false? Mark for Review
(1) Points
True
False (*)
Correct
1.
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short
2.
< (*)
<= (*)
=
!= (*)
All of the above.
3.
What is the output of the following lines of code?
int j=6,k=4,m=12,result;
result=j/m*k;
System.out.println(result);
2
0 (*)
48
24
4.
A local variable has precedence over a global variable in a Java method. True or false?
True (*)
5.
False
total cost: + 40
total cost: 48
total cost: 40 (*)
"total cost: " 48
"total cost: " 40
6.
What is the result when the following code segment is compiled and executed?
7.
!(3<4&&6>6||6<=6&&7-2==6)
True (*) False
8.
In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?
True
False (*)
9.
Which of the two diagrams below illustrate the general form of a Java program?
Example A
Example B (*)
10.
In a For loop the counter is not automatically incremented after each loop iteration. Code must be
written to increment the counter. True or false?
True (*)
False
11.
When the For loop condition statement is met the construct is exited. True or false?
True
False (*)
12.
You can return to the Eclipse Welcome Page by choosing Welcome from what menu?
File
Edit
Help (*)
Close
13.
In Eclipse, when you run a Java Application, where may the results display?
Editor Window
Console View (*)
Debug View
Task List
None of the above
14.
A workspace
A physical location
A perspective (*)
All of the above
15.
What are the Eclipse Editor Area and Views used for?(Choose all correct answers)
0.571, 13 (*)
17.
Updating the input of a loop allows you to implement the code with the next element rather than
repeating the code always with the same element. True or false?
True (*)
False
18.
One advantage to using a WHILE loop over a FOR loop is that a WHILE loop always has a counter.
True or false?
True
False (*)
19.
Which of the following could be a reason to use a switch statement in a Java program?
Because it allows the code to be run through until a certain conditional statement is true.
Because it allows the program to run certain segments of code and neglect to run others based on the input
given. (*)
Because it terminates the current loop.
Because it allows the user to enter an input in the console screen and prints out a message that the user input was
successfully read in.
20.
false?
In Java, an instance field referenced using the this keyword generates a compilation error. True or
True
21.
False (*)
Consider
A constructor must have the same name as the class it is declared within. True or false?
True (*)
False
23.
Which of the following keywords are used to control access to the member of a class?
24.
default
public (*)
class
All of the above.
None of the above.
Which of the following creates a method that compiles with no errors in the class?
(*)
What operator do you use to call an object's constructor method and create a new object?
+
new (*)
instanceOf
27.
Which of the following declares a one dimensional array name scores of type int that can hold 14
values?
int scores;
int[] scores=new int[14]; (*)
int[] scores=new int[14];
int score= new int[14]
28.
What is the output of the following segment of code if the command line arguments are "a b c d e f"?
1
3
5
6 (*)
30.
Which of the following declares a one dimensional array named names of size 8 so that all entries can
be Strings?
String names=new String[8];
String[] name=new Strings[8];
String[] names=new String[8]; (*)
String[] name=String[8];
31.
String s="\\\\\
System.out.println(s);
"\\\\\"
\\\\\\\\
\\
\\\\ (*)
32.
88888 (*)
88888888
1010778
101077810109
ArrayIndexOutofBoundsException is thrown
33.
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?
s1 == s2
s1 = s2
s3 == s1 (*)
s1.equals(s2)
s3.equals(s1)
34.
How would you use the ternary operator to rewrite this if statement?
If an exception is thrown by a method, where can the catch for the exception be?
39.
Which of the following is the correct way to call an overriden method needOil() of a super class Robot
in a subclass SqueakyRobot?
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
40.
41.
False
42.
43.
Static classes are designed as thread safe class instances. True or false?
True
False (*)
44.
Public static variables can't have their value reset by other classes. True or false?
True
False (*)
45.
Choose the correct implementation of a public access modifier for the method divide.
divide(int a, int b, public) {return a/b;}
public divide(int a, int b) {return a/b;} (*)
divide(int a, int b) {public return a/b;}
divide(public int a, public int b) {return a/b;}
46.
49.
Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In an attempt to
get organized, Joe wants to create a program that will store his textbooks in one group of books, but he wants to
make each book type the subject of the book (i.e. MathBook is a book). How could he store these different
subject books into a single array?
By ignoring the subject type and initializing all the book as objects of type Book.
By overriding the methods of Book.
Using polymorphism. (*)
This is not possible. Joe must find another way to collect the books.
50.
What is Polymorphism?
A way of redefining methods with the same return type and parameters.
A way to create multiple methods with the same name but different parameters.
A class that cannot be initiated.
The concept that a variable or reference can hold multiple types of objects. (*)
1.
What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
[Correct]
Correct
2.
When converting gallons to liters its best to put the
calculation result into a variable with a _______________ data type.
Mark for
Review
(1) Points
int
double (*)
boolean
[Correct]
Correct
3.
A workspace is:
(1) Points
The physical location onto which you will store and save your files.
The location where you can have one or more stored perspectives.
[Incorrect]
4.
_______________.
(1) Points
A workspace
A physical location
A perspective (*)
[Correct]
Correct
5.
True or false?
(1) Points
True
False (*)
[Correct]
6.
Correct
(1) Points
[Correct]
Correct
7.
total cost: + 40
total cost: 48
[Correct]
Oracle?
Correct
8.
Which of the following instantiates a String named name to
Mark for Review
(1) Points
String name;
String Oracle="name";
String name="name";
[Correct]
Correct
9.
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
s1 == s2
s1 = s2
s3 == s1 (*)
s1.equals(s2)
s3.equals(s1)
2. Which line of Java code will assign the value of the square root of 11 to a va
double a=11^(1/2);
double a=sqrt(11);
int a=Math.sqrt(11);
double a=Math.sqrt*11;
double a=Math.sqrt(11); (*)
Correct
3. The ______________ is the location into which you will store and save your file
Perspective
Workspace (*)
Editor
None of the above
Correct
4. A workspace is:
True
False (*)
Correct
Next
Page 1 of 10
Summary
6. You can return to the Eclipse Welcome Page by choosing Welcome from wha
File
Edit
Help (*)
Close
Correct
7. A perspective is described as:
What is printed?
88888 (*)
88888888
1010778
101077810109
ArrayIndexOutofBoundsException is thrown
Incorrect. Refer to Section 4 Lesson
Previous
Next
Page 2 of 10
Summary
What is printed?
Cayrbniz
CayrbnizCayrbniz
yr (*)
ay
ArrayIndexOutofBoundsException is thrown
Incorrect. Refer to Section 4 Lesson
12. Given the code:
String s = new String("abc");
Which of the following statements will change the length of s to the largest
s.trim()
s.replace("a", "aa")
s.substring(2)
s.toUpperCase()
\\\\
\\\\\\\ (*)
\\\\\\\\\\\\\\
\\
Correct
14. The following code is an example of creating a String reference:
String s;
True or false?
True (*)
False
Correct
Section 5
(Answer all questions in this section)
15. How many times will the following loop be executed?
What is the value of x after the loop has finished?
What is the value of count after the loop has finished?
int count = 17;
int x = 1;
while(count > x){
x*=3;
count-=3;
}
4; 8; 27
3; 27; 8 (*)
5; 27; 8
5; 30; 5
3; 9; 11
Correct
Previous
Page 3 of 10
Next Summary
16. One advantage to using a while loop over a for loop is that a while
True
False (*)
17. Updating the input of a loop allows you to implement the code wit
True (*)
False
Correct
True (*)
False
20. How would you use the ternary operator to rewrite this if statemen
if (balance < 500)<
fee = 10;
else
fee = 0;
fee = ( balance < 500) ? 0 : 10;
Previous
Next
Page 4 of 10
Summary
21. Which of the following declares a one dimensional array name sco
int scores;
int[] scores=new int[14]; (*)
int[] scores=new scores int[14];
int score= new int[14];
246642
222222
This code doesn't compile.
int number[];
float []averages;
double marks[5];
counter int[]; (*)
Correct
Selection Sort
Merge Sort
Bubble Sort (*)
Sequential Search
Binary Search
Previous
Page 5 of 10
Next Summary
26. Which of the following is the correct lexicographical order for the c
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}
Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above
True (*)
False
True
False (*)
Correct
Section 7
Previous
Page 6 of 10
Next Summary
31. Which of the following is the correct way to call an overriden meth
Robot.needOil(SqueakyRobot);
SqueakyRobot.needOil();
super.needOil(); (*)
needOil(Robot);
True (*)
False
Correct
33. What is encapsulation?
True (*)
False
Correct
True
False (*)
Previous
Page 7 of 10
Next Summary
True (*)
False
Correct
37. If we override the toString() method with the code below, what would be the
True
False (*)
Incorrect. Refer to Section 7 Lesson
40. A class can only have one constructor. True or false?
True
False (*)
Incorrect. Refer to Section 7 Lesson
Previous
Page 8 of 10
Next Summary
31
32
10
11 (*)
Incorrect. Refer to Section 7 Lesson
42. What is the output of the following code segment:
int n = 13;
System.out.print(doNothing(n));
System.out.print(" ", n);
where the code from the method doNothing is:
public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}
1.75, 13
0.571, 21
1.75, 21
0.571, 13 (*)
Incorrect. Refer to Section 7 Lesson
43. What is true about the code below:
Car car1=new Car();
Car car2=new Car();
car2=car1;
(Choose all correct answers)
Previous
Page 9 of 10
Next
Summary
Methods
Parameters
Overload constructors
Access modifiers (*)
Correct
47. Which of the following correctly defines overloading?
counter("one","two",String[] num
Previous
Page 10 of 10
Summary
Which of
the
following
defines a
driver
class?
Mark for
Review
(1) Points
Mark for
Review
(1) Points
alligator (*)
albatross alligator
albatross
a1
Correct
4. Which of the following instantiates a String named name to Oracle?
Mark for
Review
(1) Points
String name;
String Oracle="name";
String name="name";
String name="Oracle"; (*)
Correct
5. Consider the following code snippet.
Mark for
Review
(1) Points
What is printed?
0
1 (*)
2
11
12
Correct
6What will the
. following code
segment output?
String
s="\\\n\"\n\\\n\"";
System.out.println(s
);
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Correct
7. The following program prints "Not Equal". True or false?
Mark
for
Review
(1) Points
True
False (*)
Correct
8. For every opening curly brace { there does not need to be a
closing curly brace} for the program to compile without
error. True or False?
True
False (*)
Correct
Mark
for
Review
(1) Points
Mark
for
Review
(1) Points
Perspective
Workspace (*)
Editor
None of the above
Correct
10. When converting gallons to liters its best to put the
calculation result into a variable with a _______________
data type.
Mark
for
Review
(1) Points
int
double (*)
boolean
None of the above
Correct
11.What
symbols
are
required
for a
compiler
to ignore
a
comment
?
// (*)
/*
*/
/*/
Incorrect. Refer to Section 4
Lesson 1.
12. Eclipse does not provide views to help you
navigate a hierarchy of information. True or
False?
(1) Points
True
False (*)
Correct
13. A local variable has precedence over a global
variable in a Java method. True or false?
True (*)
False
Correct
14. Which of the following is not a legal name for a
variable?
2bad (*)
zero
theLastValueButONe
year2000
Correct
Section 5
(Answer all questions in this section)
15. Why are loops useful?
the
comment
"//your
answer
here" in
the code
below if
the code
is meant
to take no
action
when i %
2 is 0 (in
other
words
when i is
even)?
(1) Points
for(int i =
0; i < 10;
i++)
{<br> if(i
%2 == 0)
//your
answer
here
else
k+=3;
}
continue; (*)
break;
return;
k+=1;
Correct
17. What is the output of the following code
segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num);
-2 (*)
1
0
2
Correct
18. Consider that a Scanner has been initialized such
that:
Scanner in = new Scanner(System.in);
Switch
Case
Break
Default (*)
None of the above
Correct
20. The three logic operators in Java are:
followi
ng
declares
a one
dimensi
onal
array
name
scores
of type
int that
can
hold 14
values?
(1) Points
int scores;
int[] scores=new int[14]; (*)
int[] scores=new scores int[14];
int score= new int[14];
Correct
27. Which of the following declares and initializes a one
dimensional array named words of size 3 so that all
entries can be Strings?
It is missing a semicolon.
It does not compile. (*)
It gives you an out of bounds exception.
There is nothing wrong with this code.
Incorrect. Refer to Section 6 Lesson 3.
Section 7
(Answer all questions in this section)
30. The following code creates an object of type Animal.
True or false?
Animal a=new Animal();
True (*)
False
Correct
3The
1.follow
ing
code
create
s an
object
of
type
Horse:
Whale
a=ne
w
Whale
();
True
False (*)
Correct
32. The basic unit of encapsulation in
Java is the primitive data type. True or
false?
True
False (*)
Correct
33. The following statement compiles and
executes. What do you know for
certain?
tree.grows(numFeet);
numFeet must be an int.
tree must be the name of the class.
grows must be the name of an
instance field.
grows must be the name of a
method. (*)
tree must be a method.
Correct
34. A class can only have one constructor.
True or false?
True
False (*)
Correct
35. Which of the following creates a class
named Student with one constructor,
and 2 instance variables, name and
gpa?
public class Student { private String
name; private float gpa; }
public class Student private String
name; private float gpa; Student();
Classes
Methods
Local variables
Method parameters
All of the above (*)
Correct
37. Which of the following would be
most beneficial for this scenario?
Joe is a college student who has a
tendency to lose his books. Replacing
them is getting costly. In an attempt to
get organized, Joe wants to create a
program that will store his textbooks
in one group of books, but he wants to
make each book type the subject of
the book (i.e. MathBook is a book).
How could he store these different
subject books into a single array?
By ignoring the subject type and
initializing all the book as objects of
type Book.
By overriding the methods of Book.
Using polymorphism. (*)
This is not possible. Joe must find
True (*)
False
Incorrect. Refer to
Section 7 Lesson 3.
40. Any instance of the same class can
assign a new value to a static variable.
True or false?
True (*)
False
Correct
4The
1base
.case
con
diti
on
can
wor
k
with
a
con
stan
t or
vari
able
.
Tru
e or
fals
e?
True (*)
False
Correct
42.It is possible to overload a method that is not
a constructor. True or False?
True (*)
False
Correct
43.Identify the error(s) in the class below.
Choose all that apply.
(*)
Incorrect. Refer
to Section 7
Lesson 4.