Chapter 10 JAVA

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

A

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

A

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

A

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

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

D

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

D

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

D

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

C

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

T

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.

B

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

B

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

B

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

B

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.

C

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

C

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)

C

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

D

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.

D

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

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

T

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

A

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

A

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

A

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

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

A

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"

A

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

B

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

B

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.

B

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

B

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

B

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

B

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

C

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

C

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.

C

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

C

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

D

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

D

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

D

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

D

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

A

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

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.

A

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.

A

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.

A

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.

A

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

C

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

C

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

D

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.

D

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

D

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. all of the characteristics of the general object plus additional characteristics

D

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

D

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

D


Kaugnay na mga set ng pag-aaral

chapter 11- Adding the public sector

View Set

Ocular Anatomy Exam II Anterior Chamber

View Set

Fin 303 chap 1&2 review questions

View Set

Maternity Case 5: Fatime Sanogo (Exam 2)

View Set

Patho Exam 4 CH 24 Alterations Female Repro

View Set