JF Section 7 Quiz

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Jf section 7 quiz

Test: JF Section 7 Quiz


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 7
(Answer all questions in this section)
1. The final keyword makes a static variable act like a constant. True or
false?
Mark for Review

(1) Points
True (*)
False
Correct

2. You can assign new values to static variables by prefacing them with
the this keyword and a dot or period. True or false?
Mark for Review

(1) Points
True (*)
False
Correct

3. Static classes can't return instances of the parent class when the
parent class uses a private constructor. True or false?
Mark for Review

(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 3.

4. Identify the step (s) in creating a Triangle Applet that displays two
triangles.
Mark for Review

(1) Points
Draw the triangle using the inherited fillPolygon method. (*)
Extend Applet class to inherit all methods including paint. (*)
Override the paint method to include the triangles. (*)
Run and compile your code. (*)
Draw the 2nd triangle using the inherited fillPolygon method. (*)
Incorrect. Refer to Section 7 Lesson 5.

5. 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
6. What is the Java keyword final used for in a program?
Mark for Review

(1) Points
It permits redefining methods of a parent class inside the child class, with
the same name, parameters, and return type.
It terminates the program.
It permits access to the class variables and methods from anywhere.
There is no such keyword in Java.
It restricts a class from being extendable and restricts methods from
being overridden. (*)
Incorrect. Refer to Section 7 Lesson 5.

7. It is possible to return an object from a method. True or false?


Mark for Review

(1) Points
True (*)
False
Correct
8. A team is working on a coding project. They desire that all portions of
their code should have access to the classes that they write. What access
modifier should be used for each class?
Mark for Review

(1) Points
public (*)
protected
private
default
All of the above
Correct

9. Identify the error(s) in the class below. Choose all that apply.

Mark for Review

(1) Points
No method named min is defined. (*)
Final cannot be used as an access modifier.
The parameters must be the same for all methods with the same name.
Two methods cannot have the same name.
Private cannot be used as an access modifier.
Incorrect. Refer to Section 7 Lesson 2.

10. The constructor of a class has the same name as the class. True or
false?
Mark for Review

(1) Points
True (*)
False
Correct

Test: JF Section 7 Quiz


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 7
(Answer all questions in this section)
11. Which of the following creates a method that compiles with no errors
in the class?
Mark for Review

(1) Points

(*)
All of the above.
None of the above.
Incorrect. Refer to Section 7 Lesson 1.

12. What is garbage collection in the context of Java?


Mark for Review

(1) Points
The operating system periodically deletes all of the Java files available on
the system.
Any package imported in a program and not used is automatically
deleted.
When all references to an object are gone, the memory used by the
object is automatically reclaimed. (*)
The JVM checks the output of any Java program and deletes anything that
does not make sense.
Incorrect. Refer to Section 7 Lesson 1.

13. What is encapsulation?
Mark for Review

(1) Points
A programming philosophy that promotes simpler, more efficient coding
by using exiting code for new applications.
A programming philosophy that promotes protecting data and hiding
implementation in order to preserve the integrity of data and
methods. (*)
A structure that categorizes and organizes relationships among ideas,
concepts of things with the most general at the top and the most specific
at the bottom.
A keyword that allows or restricts access to data and methods.
Incorrect. Refer to Section 7 Lesson 4.

14. What does it mean to inherit a class?


Mark for Review

(1) Points
The access specifier has been set to private.
A way of organizing the hierarchy of classes.
Extending a method from a superclass.
The subclass (or child class) gains access to any non-private methods and
variables of the superclass (or parent class). (*)
Incorrect. Refer to Section 7 Lesson 4.

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

Test: JF Section 7 Quiz


Review your answers, feedback, and question scores below. An asterisk
(*) indicates a correct answer.

Section 7
(Answer all questions in this section)
1. Which segment of code represents a correct way to call a variable
argument method counter that takes in integers as its variable argument
parameter?
Mark for Review

(1) Points
counter(1, 5, 8, 17, 11000005); (*)
counter("one","two",String[] nums);
counter(String a, int b);
counter(int[] numbers);
Incorrect. Refer to Section 7 Lesson 2.

2. A team is working on a coding project. They desire that all portions of
their code should have access to the classes that they write. What access
modifier should be used for each class?
Mark for Review

(1) Points
public (*)
protected
private
default
All of the above
Correct

3. Which of the following specifies accessibility to variables, methods, and


classes?
Mark for Review

(1) Points
Overload constructors
Access modifiers (*)
Parameters
Methods
Correct

4. Identify the step (s) in creating a Triangle Applet that displays two
triangles.
Mark for Review

(1) Points
Draw the triangle using the inherited fillPolygon method. (*)
Draw the 2nd triangle using the inherited fillPolygon method. (*)
Override the paint method to include the triangles. (*)
Run and compile your code. (*)
Extend Applet class to inherit all methods including paint. (*)
Correct

5. If Sandal extends Shoe, it is possible to declare an object such that

Sandal s = new Shoe();


Mark for Review

(1) Points
True
False (*)
Incorrect. Refer to Section 7 Lesson 5.
6. Which of the following would be most beneficial for this scenario?

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?

Mark for Review

(1) Points
By overriding the methods of Book.
By ignoring the subject type and initializing all the book as objects of type
Book.
Using polymorphism. (*)
This is not possible. Joe must find another way to collect the books.
Incorrect. Refer to Section 7 Lesson 5.

7. What does it mean to inherit a class?


Mark for Review

(1) Points
The access specifier has been set to private.
The subclass (or child class) gains access to any non-private methods and
variables of the superclass (or parent class). (*)
A way of organizing the hierarchy of classes.
Extending a method from a superclass.
Correct

8. 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. 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.
Yes. A subclass inherits full access to all contents of its super class.
Correct

9. Which of the following correctly describes the use of the keyword


super?
Mark for Review

(1) Points
A keyword that allows subclasses to access methods, data, and
constructors from their parent class. (*)
A keyword that restricts access to only inside the same class.
A keyword that allows access from anywhere.
A keyword that signals the end of a program.
Correct

10. Which of the following creates a method that compiles with no errors


in the class?
Mark for Review

(1) Points

(*)

All of the above.


None of the above.
Correct
11. What is garbage collection in the context of Java?
Mark for Review

(1) Points
The operating system periodically deletes all of the Java files available on
the system.
Any package imported in a program and not used is automatically
deleted.
When all references to an object are gone, the memory used by the
object is automatically reclaimed. (*)
The JVM checks the output of any Java program and deletes anything that
does not make sense.
Correct

12. Which of the following creates an instance of the class below?

Mark for Review

(1) Points
ThisClass t=new ThisClass(5); (*)
ThisClass t;
ThisClass t=new ThisClass(3,4);
ThisClass t=new ThisClass();
Correct

13. Static classes can return instances of their parent class. True or false?
Mark for Review

(1) Points
True (*)
False
Correct
14. There is only one copy a static class variable in the JVM. True or
false?
Mark for Review

(1) Points
True (*)
False
Incorrect. Refer to Section 7 Lesson 3.

15. Public static variables can't have their value reset by other classes.
True or false?
Mark for Review

(1) Points
True
False (*)
Correct

You might also like