0% found this document useful (0 votes)
337 views

Java Fundamental Final Exam

1. The document contains a section of multiple choice questions about Java strings, operators, and control structures. 2. It asks about the validity of string operations, the use of the == operator to compare strings, and code snippets containing strings, mathematical operations, and control structures like switch statements. 3. The questions are marked as correct or incorrect along with suggestions to refer back to lessons in the referenced sections for more information.

Uploaded by

UchaPutra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
337 views

Java Fundamental Final Exam

1. The document contains a section of multiple choice questions about Java strings, operators, and control structures. 2. It asks about the validity of string operations, the use of the == operator to compare strings, and code snippets containing strings, mathematical operations, and control structures like switch statements. 3. The questions are marked as correct or incorrect along with suggestions to refer back to lessons in the referenced sections for more information.

Uploaded by

UchaPutra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Section 4

(Answer all questions in this section)


1Suppose that str1 and str2 are two strings. Which of the statements or
Mark for
. expressions are valid?
Review
(1) Points
String str3 = str1 - str2;
str1 += str2; (*)
str1 >= str2
Str1 -= str2;

Correct
2The following program prints "Not Equal". True or false?
Mark for
.
Review
(1) Points

True
False (*)

Incorrect. Refer to Section 4 Lesson 4.


3The == operator can be used to compare two String objects. The result is
Mark for
. always true if the two strings are have the exact same characters in each
Review
position of the String. True or false?
(1) Points
True
False (*)

Incorrect. Refer to Section 4 Lesson 4.


4What will the following code segment output?
Mark for
.
Review
String s="\\\n\"\n\\\n\"";
(1) Points
System.out.println(s);
\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Correct
5Which of the following creates a String reference named s and instantiates
Mark for
. it?
Review
(1) Points
(Choose all correct answers)
String s=""; (*)
s="s";
String s;
String s=new String("s"); (*)

Incorrect. Refer to Section 4 Lesson 4.

Page 1 of 10

Section 4
(Answer all questions in this section)
6. For every opening curly brace { there does not need to be a
Mark for Review
closing curly brace} for the program to compile without
(1) Points
error. True or False?
True
False (*)

Incorrect. Refer to Section 4 Lesson 1.


7. Multiple windows are used when more than one file is open
Mark for Review
in the edit area. True or False?
(1) Points
True
False (*)

Correct
8. In Eclipse, when you run a Java Application, the results are
Mark for Review
displayed in a new window. True or False?
(1) Points
True
False (*)

Correct
9. Eclipse does not provide views to help you navigate a
Mark for Review
hierarchy of information. True or False?
(1) Points
True
False (*)

Correct
10. The ______________ is the location into which you will
Mark for Review
store and save your files.
(1) Points
Perspective
Workspace (*)
Editor
None of the above

Incorrect. Refer to Section 4 Lesson 1.

Page 2 of 10

he
Mark for Review
following
(1) Points
defines a
package
keyword:
Defines where this class lives relative
to other classes, and provides a level of
access control. (*)
Provides the compiler information that
identifies outside classes used within
the current class.
Precedes the name of the class.

Incorrect. Refer to Section 4 Lesson 2.


12. Which of the following defines an object
Mark for Review
class?
(1) Points
Contains a main method and other
static methods.
Contains classes that define objects.
(*)
Contains a main method, a package,
static methods, and classes that define
objects.
None of the above.

Correct
13. What two values can a boolean variable
Mark for Review
have?
(1) Points
Numbers and characters
True and false (*)
Relational and logic operators
Arithmetic and logic operators
Integers and floating point types

Correct
14. What is the result when the following code
Mark for Review
segment is compiled and executed?
(1) Points
int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p);
Syntax error "sqrt(double) in
java.lang.Math cannot be applied to
int"
4.0 is displayed (*)
2.2 is displayed
5.656854249492381 is displayed
ClassCastException

Incorrect. Refer to Section 4 Lesson 3.

Section 5
(Answer all questions in this section)
15. The six relational operators in Java are:
Mark for Review
(1) Points
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>

Correct

Page 3 of 10
Section 5
(Answer all questions in this section)
16. Which of the following correctly
Mark for Review
matches the switch statement
(1) Points
keyword to its function?
(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 (*)
Incorrect. Refer to Section
5 Lesson 1.
17. Determine whether this boolean
Mark for Review
expression evaluates to true or
(1) Points
false:

!(3<4&&6>6||6<=6&&7-2==6)
True (*)
False

Incorrect. Refer to Section


5 Lesson 1.
18. In a for loop the counter is not
Mark for Review
automatically incremented after
(1) Points
each loop iteration. Code must
be written to increment the
counter. True or false?
True (*)
False

Correct
19. Why are loops useful?
Mark for Review
(1) Points
They save programmers
from having to rewrite code.
They allow for repeating
code a variable number of
times.
They allow for repeating
code until a certain argument
is met.
All of the above. (*)

Correct
20. When the for loop condition
Mark for Review
statement is met the construct is
(1) Points
exited. True or false?
True
False (*)

Correct

Page 4 of 10
Binary
Mark for
searches
Review
can be
(1) Points
performe
d on
sorted
and
unsorted
data.
True or
false?
True
False (*)

Incorrect. Refer to Section 6 Lesson 2.


22. A sequntial search is an iteration through the array that
Mark for
stops at the index where the desired element is found. True
Review
or false?
(1) Points
True (*)
False

Correct
23. Which of the following is the correct lexicographical order
Mark for
for the conents of the int array?
Review
(1) Points
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83} (*)

Incorrect. Refer to Section 6 Lesson 2.


24. Which of the following is a sorting algorithm that involves
Mark for
repeatedly incrementing through the array and swapping 2
Review
adjacent values if they are in the wrong order until all
(1) Points
elements are in the correct order?
Selection Sort
Merge Sort
Bubble Sort (*)
Sequential Search
Binary Search

Incorrect. Refer to Section 6 Lesson 2.


25. What will be the content of the array variable table after
Mark for
executing the following code?
Review
(1) Points

111
011
001
100
010
001
100
110
1 1 1 (*)
001
010
100
Incorrect. Refer to Section 6 Lesson 1.
Section 6
(Answer all questions in this section)
26.Which of the following
Mark for Review
declares and initializes a two
(1) Points
dimensional array that can
hold 6 Object reference
types?
String[] array=new
String[6];
Object array=new
Object[6];
Object[][] array=new
Object[2][3]; (*)
String[][]
array=String[6];
Correct
27.Which of the following
Mark for Review
declares and initializes a one
(1) Points
dimensional array named
values of size 5 so that all
entries contain 1?
int[] values={1,1,1,1,1};
(*)
int[] values={1};
int values={1,1,1,1,1};
int
values[]={1,1,1,1,1,1};
Incorrect. Refer to
Section 6 Lesson 1.
28.Which of the following
Mark for Review
declares a one dimensional
(1) Points
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];
Correct
29.What does it mean to catch
Mark for Review
an exception?
(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.
Incorrect. Refer to
Section 6 Lesson 3.

Section 7
(Answer all questions in this section)
30.If it is possible to inherit
Mark for Review
from an abstract class, what
(1) Points
must you do to prevent a
compiler error from
occurring?
(Choose all correct answers)
It is not possible to
inherit from an abstract
class.
Create all new methods
and variables different
from the parent class.
Override all abstract
methods from the parent
class. (*)
Declare the child class
as abstract. (*)
Correct

Page 6 of 10
Section 7
(Answer all questions in this section)
31. What is Polymorphism?
Mark for
Review
(1) Points
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. (*)
Correct
32. Abstract classes cannot implement interfaces. True or false?
Mark for
Review
(1) Points
True
False (*)

Correct
33. Which of the following creates an object from the Animal class listed
Mark for
below:
Review
(1) Points
Animal cat=new Animal();
Animal cat=Animal(50,30);
Animal cat=new Animal(50,30); (*)
Animal cat=new Animal(50);

Correct
34. Which of the following creates an instance of the class below?
Mark for
Review
(1) Points

ThisClass t=new ThisClass();


ThisClass t;
ThisClass t=new ThisClass(3,4);
ThisClass t=new ThisClass(5); (*)

Incorrect. Refer to Section 7 Lesson 1.


35. Which of the following creates a method that compiles with no errors
Mark for
in the class?
Review
(1) Points
(*)

All of the above.


None of the above.

Incorrect. Refer to Section 7 Lesson 1.

Page 7 of 10
Section 7
(Answer all questions in this section)
36. Java's garbage collection is when
Mark for Review
all references to an object are
(1) Points
gone, the memory used by the
object is automatically
reclaimed. True or false?
True (*)
False

Correct
37. If the return type from a method
Mark for Review
is boolean then 2.5 is a valid
(1) Points
return value. True or false?
True
False (*)
Correct
38. A class always has a constructor.
Mark for Review
True or false?
(1) Points
True (*)
False

Correct
39. Which segment of code
Mark for Review
represents a correct way to
(1) Points
define a variable argument
method?
String easyArray(String ...
elems) {//code} (*)
String easyArray(... String
elems) {//code}
String ... easyArray(String
elems) {//code}
Integer easyArray ... (int
elems) {//code}
Correct
40. How is it possible for
Mark for Review
overloading to work?
(1) Points
There is no such thing as
overloading.
The code has to be declared
as private.
The interpreter doesn't care
what you name your
constructors.
Java Virtual Machine
searches until it finds a
constructor name and
argument type match. (*)
Correct

Page 8 of 10
Section 7
(Answer all questions in this section)
41. Which of the following specifies
Mark for Review
accessibility to variables,
methods, and classes? (1) Points
Methods
Parameters
Overload constructors
Access modifiers (*)

Correct
42. Which of the following could be
Mark for Review
a reason to return an object?
(1) Points
Because you wish to be able
to use that object inside of
the method.
It has faster performance
than returning a primitive
type.
The method makes changes
to the object and you wish to
continue to use the updated
object outside of the method.
(*)
None of the above. It is not
possible to return an object.
Correct
43. Which of the following is the
Mark for Review
definition for a variable
(1) Points
argument method?
A way to create a new class.
Specifies accessibility to
code.
Having more than one
constructor with the same
name but different
arguments.
A type of argument that
enables calling the same
method with a different
number of arguments. (*)
Correct
44. A static variable is always
Mark for Review
publicly available. True or false?
(1) Points
True
False (*)

Correct
45. Static methods can't change any
Mark for Review
class variable values at run-time.
(1) Points
True or false?
True
False (*)

Correct

Page 9 of 10
Section 7
(Answer all questions in this section)
46. Non-final static class variables
Mark for Review
should be private to prevent
(1) Points
changes from other classes. True
or false?
True (*)
False

Incorrect. Refer to Section


7 Lesson 3.
47. Why is it not possible to extend
Mark for Review
more than one class at a time in
(1) Points
an inheritance hierarchy chain?
It is not necessary
considering all public
content is passed from super
class to subclass and further
to their subclass and that
subclass' subclass and so on.
(*)
Because the computer
cannot handle code that
complex.
To prevent confusion for the
programmer.
It is possible to extend more
than one class at a time.
Correct
48. According to the following class
Mark for Review
declaration, runSpeed can be
(1) Points
modified in class Cat. True or
false?

public class Tiger extends Cat{


public int runSpeed;
}
True
False (*)

Correct
49. Which of the following correctly
Mark for Review
describes the use of the keyword
(1) Points
super?
A keyword that restricts
access to only inside the
same class.
A keyword that allows
subclasses to access
methods, data, and
constructors from their
parent class. (*)
A keyword that signals the
end of a program.
A keyword that allows
access from anywhere.
Correct
50. Why are hierarchies useful for
Mark for Review
inheritance?
(1) Points
They keep track of where
you are in your program.
They restrict a superclass to
only have one subclass.
They organize constructors
and methods in a simplified
fashion.
They are used to organize
the relationship between a
superclass and its subclasses.
(*)
Correct

Page 10 of 10

You might also like