Test JAVA Fundamentals Final Exam
-
Upload
darko-savic -
Category
Documents
-
view
3.397 -
download
263
description
Transcript of Test JAVA Fundamentals Final Exam
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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.
What is printed?Mark for Review(1) Points
55555
87658
AtlanticPacificIndianArcticSouthern
Code does not compile
ArrayIndexOutofBoundsException is thrown (*)
Incorrect. Refer to Section 4 Lesson 4.
5.The following program prints "Not Equal":
True or false?Mark for Review(1) Points
True (*)
False
Correct
Page 1 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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
PreviousPage 2 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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?
int x = 22, y = 10;double p = Math.sqrt( ( x + y ) /2);System.out.println(p);Mark for Review(1) Points
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
PreviousPage 3 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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?
if (gender == "female") System.out.print("Ms.");elseSystem.out.print("Mr.");Mark for Review(1) Points
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?
int num = 7;while(num >= 0){num -= 3;}System.out.println(num);Mark for Review(1) Points
-2 (*)
1
0
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
PreviousPage 4 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 6
(Answer all questions in this section)
21.What will array arr contain after the following code segment has been executed?
int [] arr = {5, 4, 2, 1, 0};for (int i = 1; i < arr.length;
i++)
{arr[i - 1] += arr[i];}Mark for Review(1) Points
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 10 1 10 0 1
1 0 00 1 00 0 1
1 0 01 1 01 1 1 (*)
0 0 10 1 01 0 0
Incorrect. Refer to Section 6 Lesson 1.
24.The following array declaration is valid. True or false?
int[] y = new int[5];Mark for 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. Everything that follows the semicolon is interpreted as code outside of the loop. True or false?Mark for Review(1) Points
True
False (*)
Correct
PreviousPage 5 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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 on until the array is sorted. True or false?Mark for Review(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
Tree grandfatherT = new Oak();
True or false?Mark for Review(1) Points
True (*)
False
Correct
PreviousPage 6 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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
PreviousPage 7 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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:
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;}Mark for Review(1) Points
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.
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}Mark for Review(1) Points
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
PreviousPage 8 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 7
(Answer all questions in this section)
41.What is true about the code below:
Car car1=new Car();Car car2=new Car();car2=car1;Mark for Review(1) Points
(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
PreviousPage 9 of 10NextSummary
Bottom of Form
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Top of FormSection 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
PreviousPage 10 of 10Summary
Bottom of Form
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.
Top of FormAnsweredUnansweredReviewStatusQuestionMandatory?Points AvailablePoints Awarded
Section 41412
When importing another packa...Yes11
Which of the following defin...Yes11
The following code prints 5 "...Yes11
Consider the following code s...Yes10
The following program prints ...Yes11
The String methods equals an...Yes11
The == operator tests if two...Yes11
Multiple windows are used whe...Yes10
When you open more than one ...Yes11
In a project, 1 of the classe...Yes11
In Eclipse, when you run a J...Yes11
A combination of views and e...Yes11
What is the result when the ...Yes11
Which line of Java code will...Yes11
Section 565
The following prints Yes on t...Yes11
Which of the following could...Yes10
How would you use the ternar...Yes11
All of the following are ess...Yes11
What is the output of the fo...Yes11
A counter used in a for loop...Yes11
Section 695
What will array arr contain ...Yes11
What is the output of the fol...Yes11
What will be the content of t...Yes10
The following array declarat...Yes11
A logic error occurs if an u...Yes11
Bubble Sort is a sorting alg...Yes10
Which of the following sorti...Yes10
A sequntial search is an ite...Yes11
Of the options below, what i...Yes10
Section 72119
If Oak extends Tree, it is p...Yes11
What does it mean to overrid...Yes11
What is the Java keyword fin...Yes11
Which of the following corre...Yes11
Which of the following demon...Yes11
It is possible for a subclass...Yes11
Which of the following corre...Yes11
A constructor must have the ...Yes11
What is the output of the fol...Yes10
What operator do you use to ...Yes11
Identify the driver class tha...Yes11
What is true about the code ...Yes10
Which of the following creat...Yes11
Which of the following is th...Yes11
Which of the following could...Yes11
It is possible to return an ...Yes11
Which segment of code repres...Yes11
How is it possible for overl...Yes11
Forward thinking helps when ...Yes11
Static classes can have diff...Yes11
A static variable is always ...Yes11
Bottom of Form