Chapter 10 JAVA

Ace your homework & exams now with Quizwiz!

What is required for an interface method that has a body? a. The method header must begin with the key word default. b. A class that implements the interface must override the method. c. The @Default annotation must precede the method header. d. All of these are true.

The method header must begin with the key word default.

Which of the following is the operator used to determine whether an object is an instance of a particular class? a. equals b. instanceOf c. >> d. isa

instanceOf

Which of the following is an example of a lambda expression? a. int x = x * factor; b. IntCalculator = new divider(x, 2); c. IntCalculator multiplier = x -> x * factor; d. Any of these are examples of a lambda expression.

int x = x * factor;

The __________ key word is used to call a superclass constructor explicitly a. goto b. this c. super d. extends

super

In an inheritance relationship __________. a. the subclass constructor always executes before the superclass constructor b. the superclass constructor always executes before the subclass constructor c. the constructor with the lowest overhead always executes first regardless of inheritance in subclasses d. the unified constructor always executes first regardless of inheritance

the superclass constructor always executes before the subclass constructor

What type of relationship exists between two objects when one object is a specialized version of another object? a. "is a" b. "contains a" c. "has a" d. "consists of"

"is a"

Protected class members can be denoted in a UML diagram with the __________ symbol. a. + b. - c. * d. #

#

Which of the following statements declares Salaried as a subclass of PayType? a. public class Salaried implements PayType b. public class PayType derives Salaried c. public class Salaried extends PayType d. public class Salaried derivedFrom(PayType)

public class Salaried extends PayType

In a class hierarchy __________. a. the more general classes are toward the right of the tree and the more specialized classes are toward the left b. the more general classes are toward the top of the tree and the more specialized classes are toward the bottom c. the more general classes are toward the left of the tree and the more specialized classes are toward the right d. the more general classes are toward the bottom of the tree and the more specialized classes are toward the top

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom

All fields declared in an interface __________. a. have protected access b. must be initialized in the class implementing the interface c. have private access d. are treated as final and static

are treated as final and static

When a method is declared with the __________ modifier, it cannot be overridden in a subclass. a. final b. super c. void d. public

final

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } } a. Nothing is wrong with this code. b. The method super is not defined. c. The call to the method super must be the first statement in the constructor. d. No values may be passed to super.

The call to the method super must be the first statement in the constructor.

__________ is a special type of expression used to create an object that implements a functional interface. a. lambda b. beta c. alpha d. sigma

lambda

All methods specified by an interface are __________. a. private b. public c. protected d. static

public

In the following code, what is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) { } Line 10 } a. It does not override methodA. b. It does not have a constructor. c. It does not overload methodA. d. Nothing is missing. It is a complete class.

It does not override methodA.

It is not possible for a superclass to call a subclass's method.

T

__________ tells the Java compiler that a method is meant to override a method in the superclass. a. @Override b. @Overload c. @Protected d. @Inherited

@Override

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

F

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

F

Which of the following is true about protected access? a. Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. b. Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. c. Protected members cannot be accessed by methods in any other classes. d. Protected members are actually named constants.

Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

If a class contains an abstract method __________. a. you must create an instance of the class b. the method will only have a header, but not a body, and will end with a semicolon c. the method cannot be overridden in subclasses d. All of these are true.

a. you must create an instance of the class b. the method will only have a header, but not a body, and will end with a semicolon c. the method cannot be overridden in subclasses

When an "is a" relationship exists between objects, the specialized object has __________. a. some of the characteristics of the general class, but not all, plus additional characteristics b. some, but not all, of the characteristics of the general object c. none of the characteristics of the general object d. only public and protected members of the superclass

only public and protected members of the superclass

If two methods have the same name but different signatures they are __________. a. overridden b. overloaded c. superclass methods d. subclass methods

overloaded

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC a. ClassA b. ClassB c. ClassC d. cannot tell

ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC a. ClassA b. ClassB c. ClassC d. cannot tell

ClassB

Given the following code, which statement is true? public class ClassB implements ClassA{ } a. ClassA must override each method in ClassB. b. ClassB must override each method in ClassA. c. ClassB inherits from ClassA. d. ClassA inherits from ClassB.

ClassB must override each method in ClassA

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC a. ClassA b. ClassB c. ClassC d. all are interfaces

ClassC

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement "+ "in the constructor."); } } a. This cannot be determined from the code. b. It will call the method super and pass the value 40 to it as an argument. c. It will call the constructor of ClassA that receives an integer as an argument. d. The method super will have to be defined before we can say what will happen.

It will call the constructor of ClassA that receives an integer as an argument.

Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1(); a. Line 4 b. Line 9 c. Line 14 d. This is an error and will cause the program to crash.

This is an error and will cause the program to crash.

An abstract class is not instantiated itself but serves as a superclass for other classes.

T

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

T

Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones.

T

If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.

T

When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

T

You can write a super statement that calls a superclass constructor but only in the subclass's constructor.

T

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of a. a chain of inheritance b. linear inheritance c. multiple interfaces d. cascading classes

a chain of inheritance

Replacing inadequate superclass methods with more suitable subclass methods is known as __________. a. method upgrading b. tactical inheritance c. method overriding d. method overloading

method overriding

Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1(); a. method1 on Line 4 b. method1 on Line 9 c. method1 on Line 14 d. This is an error and will cause the program to crash.

method1 on Line 9

A subclass can directly access __________. a. only protected and private members of the superclass b. all members of the superclass c. only public and private members of the superclass d. only public and protected members of the superclass

only public and protected members of the superclass

If a method in a subclass has the same signature as a method in the superclass, the subclass method __________ the superclass method. a. inherits b. overloads c. overrides d. implements

overrides

a. it must include the code necessary to initialize the superclass fields b. the superclass fields will be set to the default values for their data types c. Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes d. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

In the following code, which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public final int method2(double b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public int method2(double c){} Line 12 } a. Line 4 b. Line 5 c. Line 10 d. Line 11

Line 11

In the following code, which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 } a. Line 1 b. Line 2 c. Line 3 d. Line 4

Line 4

In the following code, which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) { } Line 10 } a. Line 6 b. Line 7 c. Line 8 d. Line 9

Line 8

A protected member of a class may be directly accessed by __________. a. methods of the same class b. methods of a subclass c. methods in the same package d. Any of these

a. methods of the same class b. methods of a subclass c. methods in the same package

If you don't provide an access specifier for a class member, the class member is given __________ access by default. a. private b. public c. protected d. package

package

In Java, a reference variable is __________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance. a. static b. dynamic c. polymorphic d. public

polymorphic

When declaring class data members it is best to declare them as __________. a. private members b. public members c. protected members d. restricted members

private members

A(n) __________ method is a method that appears in a superclass but expects to be overridden in a subclass. a. abstract b. protected c. static d. overloaded

abstract

If a subclass constructor does not explicitly call a superclass constructor, __________. a. the superclass's fields will be set to the default values for their data types b. Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes c. it must include the code necessary to initialize the superclass fields d. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree? a. UML diagram b. CRC card c. flowchart d. class hierarchy

class hierarchy

A subclass may call an overridden superclass method by __________. a. prefixing its name with the super key word and a dot (.) b. prefixing its name with the name of the superclass in parentheses c. using the extends key word before the method is called d. calling the superclass method first and then calling the subclass method

prefixing its name with the super key word and a dot (.)

A __________ member's access is somewhere between public and private. a. package b. protected c. static d. final

protected

Which of the following statements correctly specifies two interfaces? a. public class ClassA implements [Interface1, Interface2] b. public class ClassA implements (Interface1, Interface2) c. public class ClassA implements Interface1, Interface2 d. public class ClassA implements Interface1 | Interface2

public class ClassA implements Interface1, Interface2

Which key word indicates that a class inherits from another class? a. final b. super c. implements d. extends

extends

In __________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass. a. pseudocode b. a UML diagram c. a CRC card d. a hierarchy chart

a UML diagram

A class becomes abstract when you place the __________ key word in the class definition. a. super b. extends c. final d. abstract

abstract

When a subclass overloads a superclass method __________. a. both methods may be called with a subclass object b. only the subclass method may be called with a subclass object c. only the superclass method may be called with a subclass object d. neither method may be called with a subclass object

both methods may be called with a subclass object


Related study sets

Chapter 8: Socioemotional Development In Early Childhood

View Set

Ch. 2 Medical terminology for Central Service technicians

View Set

2.04 Quiz Voices of an Emerging Nation

View Set

HAZMAT: CHAPTER 13 (VIDEO QUIZ 3)

View Set

MO Life Accident and Health Insurance Producer

View Set

Computer Hardware Basics Practice Questions

View Set

EC 202 Final Exam Review (Exams 1 & 2)

View Set