Sec 4
Sec 4
4. Which line of Java code will assign the square root of 11 to 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
5. What two values can a boolean variable have? Mark for Review (1) Points
Numbers and characters
True and false (*)
Relational and logic operators
Arithmetic and logic operators
Integers and floating point types
Correct
Page 1 of 10 Next Summary
Test: Java Fundamentals Final Exam
Section 4
(Answer all questions in this section)
6. Given the following declaration, which line of Java code properly casts one type into
another without data loss?
int i=3,j=4; double y=2.54; Mark for Review (1) Points
int x=(double)2.54;
double x=i/j;
double x=(double)(i/j);
double x= double i/j;
double x=(double)i/j; (*)
Correct
7. Which of the following is a legal identifier? Mark for Review
(1) Points
7up
boolean
grand Total
apple (*)
Correct
8. In a For loop the counter is not automatically incremented after each loop iteration.
Code must be written to increment the counter. True or false? Mark for Review (1)
Points
True (*)
False
Incorrect. Refer to Section 4 Lesson 2.
9. When the For loop condition statement is met the construct is exited. True or false?
Mark for Review (1) Points
True
False (*)
Incorrect. Refer to Section 4 Lesson 2.
10. Which of the two diagrams below illustrate the general form of a Java program?
19. Which of the following correctly matches the switch statement keyword to its
function? Mark for Review (1) Points
(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 (*)
Correct
20. What is wrong with the following class declaration?
class Account{ ;
privateint number;
privateString name;;
Account;;
}
Mark for Review (1) Points
Classes cannot include strings.
Classes cannot include mixed data types.
The constructor method has no definition. (*)
There is nothing wrong.
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 5
21. Which of the following may be part of a class definition? Mark for Review (1)
Points
Instance variables
Instance methods
Constructors
All of the above. (*)
None of the above.
Incorrect. Refer to Section 5 Lesson 2.
22. The constructor method must always have at least one parameter. True or false?
Mark for Review (1) Points
True
False (*)
Correct
23. A constructor must have the same name as the class it is declared within. True or
false? Mark for Review (1) Points
True (*)
False
Correct
24. The basic unit of encapsulation in Java is the primitive data type. True or false?
Mark for Review (1) Points
True
False (*)
Correct
25. In Java, an instance field referenced using the this keyword generates a compilation
error. True or false? Mark for Review (1) Points
True
False (*)
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.
Section 6
36. 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 (*)
Incorrect. Refer to Section 6 Lesson 3.
37. Which of the following correctly matches the symbol with its function? Mark for
Review
(1) Points
(Choose all correct answers)
== (two equal signs) compares values of primitive types such as int or char. (*)
== (two equal signs) compares the values of non-primitive objects.
== (two equal signs) compares the memory location of non-primitive objects. (*)
= (single equals sign) compares the value of primitive types such as int or char.
.equals() compares the value of non-primitive objects. (*)
Incorrect. Refer to Section 6 Lesson 3.
38. What is wrong with this code?
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 Object class? Mark for Review (1) Points
(Choose all correct answers)
It is the highest superclass. (*)
It extends other classes.
Its methods can be overridden in subclasses. (*)
Its methods can be overloaded in subclasses. (*)
Correct
42. An access modifier is a keyword that allows subclasses to access methods, data,
and constructors from their parent class. True or false? Mark for Review (1) Points
True (*)
False
Correct
43. 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
44. If a variable in a superclass is private, could it be directly accessed or modified by a
subclass? Why or why not? Mark for Review (1) Points
Yes. A subclass inherits full access to all contents of its super class.
Yes. Any variable passed through inheritance can be changed, but private methods
cannot.
No. A private variable can only be modified by the same class with which it is declared
regardless of its inheritance. (*)
No. Nothing inherited by the super class can be changed in the subclass.
Correct
45. Which of the following are access specifiers? Mark for Review (1) Points
(Choose all correct answers)
protected (*)
public (*)
secured
default (no access modifier) (*)
private (*)
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 of the following correctly defines overloading? Mark for Review (1) Points
Having more than one constructor with the same name but different arguments. (*)
Having more than one constructor with different names and the same arguments.
A variable argument method that returns an array.
A type of access specifier that only allows access from inside the same class.
Correct
47. Which of the following is the correct way to code a method with a return type an
object Automobile? Mark for Review (1) Points
a) Automobile upgrade(String carA){
carA="Turbo";
return carA;}
b) Automobile upgrade(Automobile carA){
carA.setTurbo("yes");
return carA;} (*)
c) String upgrade(String carA){
carA="Turbo";
return carA;}
d) upgrade(Automobile carA) Automobile{
carA.setTurbo("yes");
return carA;}
None of the above. It is not possible to return an object.
Correct
48. Static methods can't act like "setter" methods. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 2.
49. Static classes are designed as thread safe class instances. True or false? Mark for
Review
(1) Points
True
False (*)
Correct
50. Static methods can read instance variables. True or false? Mark for Review (1)
Points
True
False (*)