100% found this document useful (1 vote)
4K views

Section 1 (Answer all questions in this section) 1. Why would a programmer use polymorphism rather than sticking to a standard array? Mark for Review (1) Points Because arrays only work using the same object type and polymorphism provides a way around this. (*) Because it is easier to add or remove objects using polymorphism even when all of the objects are of the same type. Because arrays are more complex and polymorphism simplifies them by restricting them to only contain the same type objects. A programmer wouldn't use polymorphism over a standard array. Correct Correct 2. If Sandal extends Shoe, it is possible to declare an object such that Sandal s = new Shoe(); Mark for Review (1) Points True False (*) Correct Correct 3. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the needs of the objects of the subclass. True or false?

Section 1 (Answer all questions in this section) 1. Why would a programmer use polymorphism rather than sticking to a standard array? Mark for Review (1) Points Because arrays only work using the same object type and polymorphism provides a way around this. (*) Because it is easier to add or remove objects using polymorphism even when all of the objects are of the same type. Because arrays are more complex and polymorphism simplifies them by restricting them to only contain the same type objects. A programmer wouldn't use polymorphism over a standard array. Correct Correct 2. If Sandal extends Shoe, it is possible to declare an object such that Sandal s = new Shoe(); Mark for Review (1) Points True False (*) Correct Correct 3. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the needs of the objects of the subclass. True or false? Mark for Review (1) Points True (*) False Correct Correct 4. Is there a difference between overriding a method and overloading a method? Mark for Review (1) Points Yes. Overriding is done within a single class and overloading is done through a series of superclasses and their subclasses. Yes. Overriding allows for the creation of an array of different object types and overloading restricts an array to only contain the same object types. Yes. Overriding is done in the subclass and allows for redefining a method inherited from the superclass and overloading is done within a class and allows for multiple methods with the same name. (*) No, they are the same. Correct Correct 5. What allows Java to correctly and automatically determine which method to invoke based on the type of object being referred to at the time the method is called? Mark for Review (1) Points Abstract classes Polymorphism Inheritance Dynamic Method Dispatch (*) Correct Correct 6. Which of the following are true about an abstract class? Mark for Review (1) Points (Choose all correct answers) It is possible to create objects of this type. The Java Virtual Machine does not differentiate abstract classes from concrete classes. It is possible to create references of this type. (*) It is identified by the Java keyword abstract. (*) Correct Correct 7. If we override the toString() method with the code below, what would be the result of printing? Mark for Review (1) Points It would print the array one element at a time. The console screen would display: 0 18 215 64 11 42 It would print the string returned from the method. The console screen would display: [0,18,215,64,11,42,] (*) It would print the array backwards. The console screen would display: 42 11 64 215 18 0 It would print the string returned from the method. The console screen would display: {0, 18, 215, 64, 11, 42} Correct Correct 8. 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 Correct 9. Which of the following is a goal of the object model? Mark for Review (1) Points (Choose all correct answers) Providing modular code that can be reused b

Uploaded by

Si Kecil Madun
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views

Section 1 (Answer all questions in this section) 1. Why would a programmer use polymorphism rather than sticking to a standard array? Mark for Review (1) Points Because arrays only work using the same object type and polymorphism provides a way around this. (*) Because it is easier to add or remove objects using polymorphism even when all of the objects are of the same type. Because arrays are more complex and polymorphism simplifies them by restricting them to only contain the same type objects. A programmer wouldn't use polymorphism over a standard array. Correct Correct 2. If Sandal extends Shoe, it is possible to declare an object such that Sandal s = new Shoe(); Mark for Review (1) Points True False (*) Correct Correct 3. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the needs of the objects of the subclass. True or false?

Section 1 (Answer all questions in this section) 1. Why would a programmer use polymorphism rather than sticking to a standard array? Mark for Review (1) Points Because arrays only work using the same object type and polymorphism provides a way around this. (*) Because it is easier to add or remove objects using polymorphism even when all of the objects are of the same type. Because arrays are more complex and polymorphism simplifies them by restricting them to only contain the same type objects. A programmer wouldn't use polymorphism over a standard array. Correct Correct 2. If Sandal extends Shoe, it is possible to declare an object such that Sandal s = new Shoe(); Mark for Review (1) Points True False (*) Correct Correct 3. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the needs of the objects of the subclass. True or false? Mark for Review (1) Points True (*) False Correct Correct 4. Is there a difference between overriding a method and overloading a method? Mark for Review (1) Points Yes. Overriding is done within a single class and overloading is done through a series of superclasses and their subclasses. Yes. Overriding allows for the creation of an array of different object types and overloading restricts an array to only contain the same object types. Yes. Overriding is done in the subclass and allows for redefining a method inherited from the superclass and overloading is done within a class and allows for multiple methods with the same name. (*) No, they are the same. Correct Correct 5. What allows Java to correctly and automatically determine which method to invoke based on the type of object being referred to at the time the method is called? Mark for Review (1) Points Abstract classes Polymorphism Inheritance Dynamic Method Dispatch (*) Correct Correct 6. Which of the following are true about an abstract class? Mark for Review (1) Points (Choose all correct answers) It is possible to create objects of this type. The Java Virtual Machine does not differentiate abstract classes from concrete classes. It is possible to create references of this type. (*) It is identified by the Java keyword abstract. (*) Correct Correct 7. If we override the toString() method with the code below, what would be the result of printing? Mark for Review (1) Points It would print the array one element at a time. The console screen would display: 0 18 215 64 11 42 It would print the string returned from the method. The console screen would display: [0,18,215,64,11,42,] (*) It would print the array backwards. The console screen would display: 42 11 64 215 18 0 It would print the string returned from the method. The console screen would display: {0, 18, 215, 64, 11, 42} Correct Correct 8. 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 Correct 9. Which of the following is a goal of the object model? Mark for Review (1) Points (Choose all correct answers) Providing modular code that can be reused b

Uploaded by

Si Kecil Madun
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Static
variable
s can't
use
which of
the
following
modifier
s?

Mark for Review


(1) Points

Public
Protected
Friendly (*)
Default
Private
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. You can create static class methods inside any Java class. True or
false?

Mark for
Review
(1) Points

True (*)
False
Correct
4. Which of the following statements about static methods is true?

Mark for
Review
(1) Points

They exist once per class. (*)


They exist once in each instance.
They can be overridden by a subclass.
They can access any instance variable.
They cannot access static variables declared outside the
method.

Correct
5. You can return an instance of a private class through a static
method of a different class. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct
6. You can create static classes as independent classes. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct
7. You can use an inner static class to return an instance of its outer
class container. True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
8. A linear recursive method can call how many copies of itself?

Mark for
Review
(1) Points

1 (*)
2 or more
None
Correct
9. Which case does a recursive method call last?

Mark for
Review
(1) Points

Recursive Case

Convergence Case
Basic Case
Base Case (*)
None of the above
Correct
10. A non-linear recursive method can call how many copies of itself?

Mark for
Review
(1) Points

1
2 or more (*)
None
Correct
11. A non-linear recursive method is less expensive than a linear
recursive method. True or false?

Mark for
Review
(1) Points

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

You might also like