Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
283 views

Test Java Fundamentals Final Exam

The document is a summary of a Java fundamentals exam containing multiple choice questions. It shows the questions, possible answers, and indicates the correct answers with an asterisk. The questions cover topics like importing packages, driver classes, String methods, the sqrt() method, switch statements, and the ternary operator.

Uploaded by

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

Test Java Fundamentals Final Exam

The document is a summary of a Java fundamentals exam containing multiple choice questions. It shows the questions, possible answers, and indicates the correct answers with an asterisk. The questions cover topics like importing packages, driver classes, String methods, the sqrt() method, switch statements, and the ternary operator.

Uploaded by

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

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)
1.When importing another package into a class you must import only the package classes that
will be called and not the entire package. True or false? Mark for
Review
(1) Points
True

False (*)

Correct

2.Which of the following defines a driver class?


Mark for
Review
(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

3.The following code prints 5 "a"'s to the screen:


Mark for
Review
(1) Points

True

False (*)

Correct

4.Consider the following code snippet.


Mark for
Review
(1) Points

What is printed?
55555
87658

AtlanticPacificIndianArcticSouthern

Code does not compile

ArrayIndexOutofBoundsException is thrown (*)

Incorrect. Refer to Section 4 Lesson 4.

5.The following program prints "Not Equal":


Mark for
Review
(1) Points

True or false?
True (*)

False

Correct

Page 1 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)
6. The String methods equals and compareTo perform similar functions and differ in their
return type. True or false? Mark for Review
(1) Points
True (*)

False

Correct

7. 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

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

False (*)

Incorrect. Refer to Section 4 Lesson 1.

9. When you open more than one file in Eclipse the system will __________________.
Mark for Review
(1) Points
Close the previously opened file.

Use tabs to display all files open. (*)


Put the new file opened in a View area only.

None of the above.

Correct

10. In a project, 1 of the classes must contain a main method. True or False?
Mark for Review
(1) Points
True (*)

False

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.In Eclipse, when you run a Java Application, the results are displayed in a new window.
True or False? Mark for
Review
(1) Points
True

False (*)

Correct
12.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

13.What is the result when the following code segment is compiled and executed?
Mark for
int x = 22, y = 10; Review
double p = Math.sqrt( ( x + y ) /2); (1) Points
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

Correct

14.Which line of Java code will assign the value of the square root of 11 to a variable named
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

Section 5
(Answer all questions in this section)
15.The following prints Yes on the screen. True or false?
Mark for
Review
(1) Points
True

False (*)

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
(Answer all questions in this section)
16. Which of the following could be a reason to use a switch statement in a Java program?
Mark for Review
(1) Points
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.
Incorrect. Refer to Section 5 Lesson 1.

17. 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.");
System.out.print( (gender == "female") ? "Mr." : "Ms." );

System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)

(gender == "female") ? "Mr." : "Ms." ;

(gender == "female") ? "Ms." : "Mr." ;

Correct

18. All of the following are essential to initializing a for loop, except which one?
Mark for Review
(1) Points
Initializing the iterator(i).

Having a conditional statement.

Updating the counter.

Having an if statement. (*)

Correct
19. What is the output of the following code segment?
Mark for Review
int num = 7; (1) Points
while(num >= 0)
{
num -= 3;
}
System.out.println(num);
-2 (*)

Correct

20. A counter used in a for loop cannot be initialized within the For loop header. True or
false? Mark for Review
(1) Points
True

False (*)

Correct

Previous Page 4 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
(Answer all questions in this section)
21.What will array arr contain after the following code segment has been executed?
Mark for
int [] arr = {5, 4, 2, 1, 0}; Review
for (int i = 1; i < arr.length; i++)<br> { (1) Points
arr[i - 1] += arr[i];
}
9, 6, 1, 3, 0

10, 6, 3, 1, 0

9, 6, 3, 1, 0 (*)

7, 3, 2, 1, 0

None of the above.

Correct

22.What is the output of the following segment of code?


Mark for
Review
(1) Points

456789

777777 (*)

555555

987654

This code doesn't compile.

Correct

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

1 1 1
0 1 1
0 0 1
1 0 0
0 1 0
0 0 1
1 0 0
1 1 0
1 1 1 (*)
0 0 1
0 1 0
1 0 0
Incorrect. Refer to Section 6 Lesson 1.

24.The following array declaration is valid. True or false?


Mark for
int[] y = new int[5]; Review
(1) Points
True (*)

False

Correct

25.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. Mark for
Everything that follows the semicolon is interpreted as code outside of the loop. True or Review
false? (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 6
(Answer all questions in this section)
26. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the
first index, finding the next smallest value and swapping it into the next index and so Mark for Review
on until the array is sorted. True or false? (1) Points

True

False (*)

Incorrect. Refer to Section 6 Lesson 2.

27. Which of the following sorting algorithms utilizes a "divide and conquer" technique to
sort arrays with optimal speed? Mark for Review
(1) Points
Sequential Search

Merge Sort (*)

Selection Sort

Binary Search

All of the above

Incorrect. Refer to Section 6 Lesson 2.

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

False

Correct

29. Of the options below, what is the fastest run-time?


Mark for Review
(1) Points
n

n^2
lg(n) (*)
n*lg(n)

Incorrect. Refer to Section 6 Lesson 2.

Section 7
(Answer all questions in this section)
30. If Oak extends Tree, it is possible to declare an object such that
Mark for Review
Tree grandfatherT = new Oak(); (1) Points

True or false?
True (*)

False

Correct

Previous Page 6 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)
31. What does it mean to override a method?
Mark for Review
(1) Points
It is a way to create multiple methods with the same name but different
parameters.
It allows an array to contain different object types.

It restricts the privacy of the method to only be accessible from inside the same
class.
It is a way of redefining methods of a parent class inside the child class, with the
same name, parameters, and return type. (*)
Correct

32. What is the Java keyword final used for in a program?


Mark for Review
(1) Points
It restricts a class from being extendable and restricts methods from being
overridden. (*)
It permits access to the class variables and methods from anywhere.

It permits redefining methods of a parent class inside the child class, with the
same name, parameters, and return type.
It terminates the program.

There is no such keyword in Java.

Correct
33. Which of the following correctly describes the use of the keyword super?
Mark for Review
(1) Points
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

34. Which of the following demonstrates the correct way to create an applet Battlefield?
Mark for Review
(1) Points
public class Battlefield extends Applet{...} (*)

public Applet Battlefield{...}


public class Applet extends Battlefield{...}

public class Battlefield(Applet){...}

Correct

35. It is possible for a subclass to be a superclass. True or false?


Mark for Review
(1) Points
True (*)

False

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 7
(Answer all questions in this section)
36. 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. (*)
A programming philosophy that promotes simpler, more efficient coding by using
exiting code for new applications.
It restricts access to a specified segment of code.

A programming philosophy that promotes protecting data and hiding


implementation in order to preserve the integrity of data and methods.
Correct
37. A constructor must have the same name as the class where it is declared. True or
false? Mark for Review
(1) Points
True (*)

False

Correct

38. What is the output of the following code segment:


Mark for Review
int n = 13; (1) Points
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 1.

39. What operator do you use to call an object's constructor method and create a new
object? Mark for Review
(1) Points
+

new (*)

instanceOf

Correct

40. Identify the driver class that correctly initializes employees Jane and Brandon. The
Employee class is below. Mark for 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();
}
}
Correct

Previous Page 8 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)
41. What is true about the code below:
Mark for Review
Car car1=new Car(); (1) Points
Car car2=new Car();
car2=car1;
(Choose all correct answers)
The references car1 and car2 are pointing to two Car Objects in memory.

The reference car2 points to an exact copy of the Car Object that car1 references.
(*)
There are no more Car objects in memory.

There is a Car object that car1 referenced that is now slated for removal by the
garbage collector.
There is a Car object that car2 referenced that is now slated for removal by the
garbage collector. (*)
Incorrect. Refer to Section 7 Lesson 1.

42. Which of the following creates a class named Student with one constructor, and 2
instance variables, name and gpa? Mark for Review
(1) Points
public class Student { private String name; private float gpa; }
public class Student private String name; private float gpa; Student();

public class Student { private String name; private float gpa; Student(){
name="Jane Doe"; gpa=3.0;} } (*)
public class Student { private String name; Student{ name="Jane Doe"; float
gpa=3.0; }
Correct

43. Which of the following is the definition of a constructor?


Mark for Review
(1) Points
A keyword that specifies accessibility of code.

A special method that is used to assign initial values to instance variables in a


class. (*)
A way to call a method with a variable number of arguments using an elipse.

A variable in a method declaration that gets passed into the method.

Correct

44. Which of the following could be a reason to return an object?


Mark for Review
(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

45. It is possible to return an object from a method. 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. 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

47. How is it possible for overloading to work?


Mark for Review
(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

48. Forward thinking helps when creating linear recursive methods. True or false?
Mark for Review
(1) Points
True

False (*)

Correct

49. Static classes can have different access specifiers than the parent class. True or false?
Mark for Review
(1) Points
True (*)

False

Correct
50. A static variable is always publicly available. True or false?
Mark for Review
(1) Points
True

False (*)

Correct

Previous Page 10 of 10 Summary


Test Summary: Java Fundamentals Final Exam
Click a question to return to it. You will see the response that was entered and whether or not the response was
correct. If the response was incorrect the correct answer will be displayed.
Answered Unanswered
Points Points
Review Status Question Mandatory? Available Awarded
Section 4 14 12
When importing another packa... Yes 1 1
Which of the following defin... Yes 1 1
The following code prints 5 "... Yes 1 1
Consider the following code s... Yes 1 0
The following program prints ... Yes 1 1
The String methods equals an... Yes 1 1
The == operator tests if two... Yes 1 1
Multiple windows are used whe... Yes 1 0
When you open more than one ... Yes 1 1
In a project, 1 of the classe... Yes 1 1
In Eclipse, when you run a J... Yes 1 1
A combination of views and e... Yes 1 1
What is the result when the ... Yes 1 1
Which line of Java code will... Yes 1 1
Section 5 6 5
The following prints Yes on t... Yes 1 1
Which of the following could... Yes 1 0
How would you use the ternar... Yes 1 1
All of the following are ess... Yes 1 1
What is the output of the fo... Yes 1 1
A counter used in a for loop... Yes 1 1
Section 6 9 5
What will array arr contain ... Yes 1 1
What is the output of the fol... Yes 1 1
What will be the content of t... Yes 1 0
The following array declarat... Yes 1 1
A logic error occurs if an u... Yes 1 1
Bubble Sort is a sorting alg... Yes 1 0
Which of the following sorti... Yes 1 0
A sequntial search is an ite... Yes 1 1
Of the options below, what i... Yes 1 0
Section 7 21 19
If Oak extends Tree, it is p... Yes 1 1
What does it mean to overrid... Yes 1 1
What is the Java keyword fin... Yes 1 1
Which of the following corre... Yes 1 1
Which of the following demon... Yes 1 1
It is possible for a subclass... Yes 1 1
Which of the following corre... Yes 1 1
A constructor must have the ... Yes 1 1
What is the output of the fol... Yes 1 0
What operator do you use to ... Yes 1 1
Identify the driver class tha... Yes 1 1
What is true about the code ... Yes 1 0
Which of the following creat... Yes 1 1
Which of the following is th... Yes 1 1
Which of the following could... Yes 1 1
It is possible to return an ... Yes 1 1
Which segment of code repres... Yes 1 1
How is it possible for overl... Yes 1 1
Forward thinking helps when ... Yes 1 1
Static classes can have diff... Yes 1 1
A static variable is always ... Yes 1 1

You might also like