Java Final 2/3

Ace your homework & exams now with Quizwiz!

9.7 Q1: Which of the following statements are true? A.We can use inheritance to customize existing software. B.A superclass specifies commonality. C.A superclass can be modified without modifying subclasses D.A subclass can be modified without modifying its superclass. a.All of the above. b.None of the above. c.A, B and C. d.A, B and D

*A)All of the above b) none of the above C) A, B, and C. D) A, B, and D

50) private fields of a superclass can be accessed in a subclass?

-By calling public or protected methods declared in the superclass.

Finalizers are used to:

-Clean up an object of a class before it, is garbage collected

Abstract Data Types:

-Elevate the importance of data -Are only approximation or models of real-world concepts and behaviors. -Capture tow notions, data representation and operations. *All of the above

Which statement below is not true? a) Superclass finalizers should always be called as the last statement of a subclass finalizer b.Superclass constructors should always be called as the first statement of a subclass constructor. c.Finalizers and constructors should always be declared protected so subclasses have access to the method. d)all are not true

-Finalizers and constructors should always be declared protected so subclasses have access to the method. Constructors should be declared public so classes that use their classes can instantiate them.

48) to avoid duplicating code (and possibly errors), use _, rather than _.

-Inheritance -The "copy-and-paste" approach

49)Which of the following is the superclass constructor call syntax?

-Keyword super, followed by a set of parenthesis containing the superclass constructor arguments.

Every class in Java, except ___, extends an existing class.

-Object

An advantage of inheritance is that:

-Objects of a derived class can be treated like objects of their base class

Superclass methods with this level of access cannot be called from subclasses.

-Private

When an applet container encounters an HTML file that specifies an applet to execute, the applet container automatically loads __ of the applet from the same directory as that of the HTML file.

-The .class file

51) When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?

-The program compiles and runs because the instance variables are initialized to their default values.

Accessing a superclass method through a subclass reference is:

-a syntax error

42)Which of the following is an example of a functionality that should not be "factored out" to a superclass?

-all animals lay eggs except for mammals

55) To draw on a n applet, the programmer must access the __ object in the applet's paint method.

-graphics

The term encapsulation refers to:

-hiding implementation details from clients of a class

54) When an applet container loads an applet, it calls three methods. In sequence, these methods are:

-init, start, paint

Overriding a method differs from overloading a method because:

-overridden method has the same signature

Using the protected keyword gives a member: think it is the same as this one: Using the protected keyword gives an instance variable:

-package access

57) Which method is called by the applet container when the applet is being removed from memory?

-public void destroy()

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

-super

Which of the following is not a superclass/subclass relationship?

Sailboat/Tugboat. A Sailboat is not a superclass for Tugboats. Both sailboat and tugboats would be subclasses of Boat.

53) The browser that executes an applet is generically known as the __.

applet container

Consider the classes below, declared in the same file: class A { int a; public A() { a = 7; } } class B extends A { int b; public B() { b = 8; } } Which of the statements below is not true? a.Both variables a and b are instance variables. b.After the constructor for class B is executed, the variable a will have the value 7 c.After the constructor for class B is executed, the variable b will have the value 8 d.A reference to class A can be treated as a reference to class B

d. A reference to class A can be treated as a reference to class B. The converse is true because class A is the superclass. Note that variables a and b both have package access.

Which of the following refers to a "has a" relationship instead of an "is a" relationship?

is-a = inheritance. has-a = composition eg: class A extends class B, then 'A' is a 'B' . i.e say class dog extends animal then dog is a animal. and if class A has B obj then A has a B. say class dog{ Leg leg;//here Leg is a class name //Leg's object(leg) has holds the dog class } then class dog has a class Leg.

52) The default equals implementation determines:

whether two references refer to the same object in memory


Related study sets

Macro - The Expenditure-Output Model

View Set

Credit(Credit Reports, Identity Theft, Bankruptcy & Collection Agencies)

View Set

(5) Real Estate Title Transfer - Quizzes/Exams

View Set

Acute and Chronic Illness Exam 1

View Set