Test: JF Java Fundamentals Final Exam
Test: JF Java Fundamentals Final Exam
Section 4
(Answer all questions in this section)
1. Given the code below, which of the following calls are valid?
(1) Points
s.toUpperCase()(*)
s.substring(2)(*)
s.trim()(*)
s.replace('a', 'A')(*)
s.setCharAt(1,'A')
(1) Points
12
11
3 (*)
Correct
Which of the following statements will change the length of s to the largest length?
(1) Points
s.trim()
s.replace("a", "aa")
s.substring(2)
s.toUppercase()
char c="c";
(1) Points
True
False (*)
Correct
What is printed?
(1) Points
Black
Forest
5 (*)
7
Correct
(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
(1) Points
Provides the compiler information that identifies outside classes used within
the current class.
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level
of access control.
Correct
8. Eclipse does not provide views to help you navigate a hierarchy of
information. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
9. The ______________ is the location into which you will store and save
your files.
Mark for Review
(1) Points
Perspective
Workspace (*)
Editor
None of the above
Correct
10. In Eclipse, when you run a Java Application, the results may be
displayed in the Console View. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
Previous
11. What is the purpose of the Eclipse Editor Area and Views?
Mark for Review
(1) Points
To choose the file system location to delete a file.
To modify elements.(*)
(1) Points
File
Help (*)
Edit
Close
Correct
(1) Points
double number=3e4; (*)
double number=3(e4);
double number=3*10^4;
double number=3*10e4;
Correct
(1) Points
x=7.0/2.0;
x=3.5;
double x=3.5
3.5=x; (*)
Correct
(1) Points
Rectangle
String
int (*)
Object
Correct
Previous
Section 5
(Answer all questions in this section)
(1) Points
while(*)
do-while(*)
for(*)
if/else
Correct
17. One advantage to using a while loop over a for loop is that a while loop always
has a counter. True or false?
(1) Points
True
False (*)
Correct
18. In the code fragment below, the syntax for the for loop's initialization is correct.
True or false?
(1) Points
True
False (*)
Correct
(1) Points
&,|,=
&&,!=,=
!=,=,==
Correct
20. How would you use the ternary operator to rewrite this if statement?
(1) Points
True
False (*)
Correct
Section 6
(Answer all questions in this section)
(1) Points
456789
777777 (*)
987654
555555
Correct
(1) Points
642246 (*)
642
312213
321123
Correct
24. What is the output of the following segment of code if the command line
arguments are "apples oranges pears"?
(1) Points
3 (*)
0
Correct
(1) Points
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
Correct
Previous
Section 6
(Answer all questions in this section)
(1) Points
(1) Points
A very severe non-fixable problem with interpreting and running your code.
(1) Points
Helping the interpreter compile code quicker and handle user interfaces.
Making the program easier to use for the user and reducing the possibilities of
errors occuring.
Exceptions have no use, they are just a part of the Java language.
Incorrect. Refer to Section 6 Lesson 2.
29. Which of the following correctly matches the symbol with its function?
(1) Points
= (single equals sign) compares the value of primitive types such as int or char.
== (two equal signs) compares values of primitive types such as int or char.(*)
Correct
Section 7
(Answer all questions in this section)
30. Public static variables can't have their value reset by other classes. True or
false?
(1) Points
True
False (*)
Correct
Previous
Section 7
(Answer all questions in this section)
31. Which of the following access modifiers doesn't work with a static variable?
(1) Points
public
default
friendly (*)
protected
private
Correct
(1) Points
True
False (*)
Correct
A class that inherits methods and fields from a more general class.
(1) Points
(1) Points
It is the virtual machine that translates Java code into a representation that the computer can
understand.
36. Which of the following is the proper way to set the public variable length
of the super class equal to 5 from inside the subclass?
Mark for Review
(1) Points
super.length = 5 (*)
super.length(5)
super.length() = 5
super(length = 5)
Correct
(1) Points
Classes
Methods
Local variables
Method parameters
All of the above (*)
Correct
True or false?
Mark for Review
(1) Points
True (*)
False
Correct
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?
(1) Points
By overriding the methods of Book.
This is not possible. Joe must find another way to collect the books.
Using polymorphism. (*)
By ignoring the subject type and initializing all the book as objects of type
Book.
Correct
(1) Points
Having more than one constructor with the same name but different
arguments. (*)
A variable argument method that returns an array.
A type of access specifier that only allows access from inside the same class.
Having more than one constructor with different names and the same
arguments.
Correct
Previous
41. Which of the following are access modifiers?
Mark for Review
(1) Points
secured
default (no access modifier)(*)
protected(*)
private(*)
public(*)
Correct
42. Which of the following shows the correct way to initialize a method
DolphinTalk that takes in 2 integers, dol1 and dol2, and returns the greater
int between the two?
Mark for Review
(1) Points
int DolphinTalk(dol1, dol2){ if(dol1 > dol2) return dol1; else return dol2;}
int DolphinTalk(int,int){ if(dol1 > dol2) return dol1; else return dol2;}
int DolphinTalk(int dol1,int dol2){ if(dol1 > dol2) return dol1; else return
dol2;} (*)
int DolphinTalk, int dol1,int dol2 { if(dol1 > dol2) return dol1; else return
dol2;}
All of the above
Correct
(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
(1) Points
Overload constructors
Access modifiers (*)
Parameters
Methods
Correct
45. What value will be returned when the setValue method is called?
(1) Points
38
35
36
37 (*)
Correct
Previous
46. Which of the following creates a Object from the Animal class listed
below?
(1) Points
Animal dog=new Animal(50);
Animal dog=new Animal();
Animal dog=Animal(50,30);
Animal dog=new Animal(50,30); (*)
Correct
47. The following statement compiles and executes. What do you know for
certain?
tree.grows(numFeet);
Mark for Review
(1) Points
grows must be the name of a method. (*)
numFeet must be an int.
tree must be a method.
grows must be the name of an instance field.
tree must be the name of the class.
Correct
48. The return value of a method can only be a primitive type and not an
object. True or false?
Mark for Review
(1) Points
True
False (*)
Correct
(1) Points
(*)
50. If the return type from a method is boolean then 2.5 is a valid return
value. True or false?
Mark for Review
(1) Points
True
False (*)
Correct
Previous