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 . Which of the following is not a legal name for a variable? Mark for Review (1) Points 2bad (*) zero theLastValueButONe year2000 Correct 2 . 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 3 . A _______________ is used to organize Java related files. Mark for Review (1) Points Project Workspace
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Test: Java Fundamentals Final ExamReview your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 4(Answer all questions in this section)
1.Which of the following is not a legal name for a variable?
Mark forReview
(1) Points
2bad (*)zerotheLastValueButONeyear2000
Correct
2.Select the declaration and initialization statement that will hold the letter J.
Mark forReview
(1) Points
int letter='J';float letter='J';String letter='J';char letter='J'; (*)
Correct
3.A _______________ is used to organize Java related files.
Mark forReview
(1) Points
ProjectWorkspace
Package (*)Collection
Correct
4.A combination of views and editors are referredto as _______________.
Mark forReview
(1) Points
A workspaceA physical locationA perspective (*)All of the above
Correct
5.A workspace is: Mark for
Review (1) Points
The physical location onto which you will store and save your files.The location where all projects are developed and modified.The location where you can have one or more stored perspectives.All of the above. (*)
Correct
Section 4(Answer all questions in this section)
6.Eclipse does not provide views to help you navigate a hierarchy of information. True or False?
Mark forReview
(1) Points
TrueFalse (*)
Correct
7.Multiple windows are used when more than one file is open in the edit area. True or False?
Mark forReview
(1) Points
TrueFalse (*)
Correct
8.Given the code:
String s = new String("abc");
Which of the following statements will change the length of s to the largest length?
Mark forReview
(1) Points
s.trim()s.replace("a", "aa")s.substring(2)s.toUpperCase()None of the above will change the length ofs. (*)
Correct
9.The == operator tests if two String referencesare pointing to the same String object. True or false?
Mark forReview
(1) Points
True (*)False
Correct
10.Which of the following creates a String reference named s and instantiates it?
12.The following code is an example of creating aString reference:
String s;
True or false?
Mark forReview
(1) Points
True (*)
False
Correct
13.The following defines an import keyword: Mark for
Review (1) Points
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.
Correct
14.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
Section 5(Answer all questions in this section)
15.A counter used in a for loop cannot be initialized within the For loop header. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Correct
Section 5(Answer all questions in this section)
16.Which of the following best describes a while loop?
Mark forReview
(1) Points
A loop that contains a segment of code thatis 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.In a for loop the counter is not automaticallyincremented after each loop iteration. Code must be written to increment the counter. Trueor false?
Mark forReview
(1) Points
True (*)False
Correct
18.switch statements work on all input types including, but not limited to, int, char, and
Mark forReview
String. True or false? (1) Points
TrueFalse (*)
Correct
19.Determine whether this boolean expression evaluates to true or false:
!(3<4&&6>6||6<=6&&7-2==6)
Mark forReview
(1) Points
True (*)False
Correct
20.The three logic operators in Java are: Mark for
Review (1) Points
&&, ||, ! (*)!=,=,==&&,!=,=&,|,=
Correct
Section 6(Answer all questions in this section)
21.
What is the output of the following segment of code?
Mark forReview
(1) Points
32111111 (*)1111111This code doesn't compile.
Incorrect. Refer to Section 6 Lesson 1.
22.
Which of the following declares and initializes aone dimensional array named values of size 5 so that all entries contain 1?
Which searching algorithm involves using a low, middle, and high index value to find the locationof a value in a sorted set of data (if it exists)?
Mark forReview
(1) Points
Sequential SearchMerge SortSelection SortBinary Search (*)All of the above
Correct
Section 6(Answer all questions in this section)
26.A sequntial search is an iteration through thearray that stops at the index where the desired element is found. True or false?
Mark forReview
(1) Points
True (*)False
Correct
27.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 forReview
(1) Points
TrueFalse (*)
Correct
28.Which of the following is a sorting algorithm that involves repeatedly incrementing through the array and swapping 2 adjacent values if they are in the wrong order until all elementsare in the correct order?
29.If an exception is thrown by a method, where can the catch for the exception be?
Mark forReview
(1) Points
There does not need to be a catch in this situation.The catch must be in the method that threw the exception.The catch can be in the method that threw the exception or in any other method that called the method that threw the exception.(*)The catch must be immediately after the throw.
Correct
Section 7(Answer all questions in this section)
30.All objects, in Java, are created using int. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Correct
Section 7(Answer all questions in this section)
31.
The basic unit of encapsulation in Java is the primitive data type. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Incorrect. Refer to Section 7 Lesson 1.
32.
Which of the following calls the method calculatecorrectly?
Mark forReview
(1) Points
ThisClass t=new ThisClass(); int x=t.calculate(3,4); (*)int x=calculate(3,4);ThisClass t=new ThisClass(); int x=t.calculate(3);ThisClass t=new ThisClass(); int x=t.calculate();
Correct
33.
Which of the following creates an instance of theclass below?
Identify the driver class that correctly initializes employees Jane and Brandon. The Employee class is below.
Mark forReview
(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
35.
What operator do you use to call an object's constructor method and create a new object?
Mark forReview
(1) Points
+new (*)instanceOf
Correct
Section 7(Answer all questions in this section)
36.If you inherit a class, you do not inherit theclass' constructors. True or false?
Mark forReview
(1) Points
True (*)False
Correct
37.If a variable in a superclass is private, could it be directly accessed or modified by asubclass? Why or why not?
Mark forReview
(1) Points
Yes. A subclass inherits full access to allcontents of its super class.Yes. Any variable passed through inheritance can be changed, but private methods cannot.No. A private variable can only be modifiedby the same class with which it is declaredregardless of its inheritance. (*)No. Nothing inherited by the super class
can be changed in the subclass.
Correct
38.What is encapsulation? Mark for
Review (1) Points
A keyword that allows or restricts access to data and methods.A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top andthe most specific at the bottom.A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*)
Correct
39.Which of the following show the correct UML representation of the super class Planet and its subclass Earth?
Mark forReview
(1) Points
(*)
None of the above.
Correct
40.Static classes can't return instances of the parent class when the parent class uses a private constructor. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Incorrect. Refer to Section 7 Lesson 3.
Section 7(Answer all questions in this section)
41.Public static variables can't have their valuereset by other classes. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Correct
42.A base case can handle nested conditions. Trueor false?
Mark forReview
(1) Points
True (*)False
Correct
43.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
44.Abstract classes can be instantiated. True or false?
Mark forReview
(1) Points
TrueFalse (*)
Correct
45.If an abstract class does not have implementedconstructors or methods, it should be implemented as an interface instead. True or false?
Mark forReview
(1) Points
True (*)
False
Correct
Section 7(Answer all questions in this section)
46.Which segment of code correctly defines a method that contains two objects of class Treeas parameters?
Mark forReview
(1) Points
void bloom(Tree pine, Tree oak) {//code here }; (*)Tree bloom (pine, oak) {//code here };void bloom, Tree pine, Tree oak {//code here };None of the above, objects cannot be passedas parameters.
Incorrect. Refer to Section 7 Lesson 2.
47.Which of the following is the correct way to code a method with a return type an object Automobile?
Mark forReview
(1) Points
Automobile upgrade(String carA){ carA="Turbo"; return carA;}Automobile upgrade(Automobile carA){ carA.setTurbo("yes"); return carA;} (*)String upgrade(String carA){ carA="Turbo"; return carA;}upgrade(Automobile carA) Automobile{ carA.setTurbo("yes"); return carA;}None of the above. It is not possible to
return an object.
Correct
48.Which segment of code represents a correct wayto define a variable argument method?