Deck 10: Inheritance

Full screen (f)
exit full mode
Question
You can write a super statement that calls a superclass constructor but only in the subclass's constructor.
Use Space or
up arrow
down arrow
to flip the card.
Question
Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.
Question
An abstract class is not instantiated itself but serves as a superclass for other classes.
Question
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
Question
A functional interface is simply an interface that has one abstract method.
Question
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
Question
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
Question
When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
Question
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.
Question
A __________ member's access is somewhere between public and private.

A) package
B) protected
C) static
D) final
Question
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
Question
In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
Question
If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.
Question
If two methods in the same class have the same name but different signatures, the second overrides the first.
Question
It is not possible for a superclass to call a subclass's method.
Question
When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.
Question
All methods in an abstract class must also be declared abstract.
Question
Every class has a toString method and an equals method inherited from the Object class.
Question
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.
Question
A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.
Question
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"
Question
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
Question
Which key word indicates that a class inherits from another class?

A) final
B) super
C) implements
D) extends
Question
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.
Question
__________ is a special type of expression used to create an object that implements a functional interface.

A) lambda
B) beta
C) alpha
D) sigma
Question
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.
Question
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
Question
__________ tells the Java compiler that a method is meant to override a method in the superclass.

A) @Override
B) @Overload
C) @Protected
D) @Inherited
Question
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
Question
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
Question
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
Question
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
Question
The __________ key word is used to call a superclass constructor explicitly.

A) goto
B) this
C) super
D) extends
Question
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
Question
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
Question
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
Question
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
Question
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.
Question
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.
Question
All methods specified by an interface are __________.

A) private
B) public
C) protected
D) static
Question
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) cannot tell
Question
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.
Question
A class becomes abstract when you place the __________ key word in the class definition.

A) super
B) extends
C) final
D) abstract
Question
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
Question
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.
Question
Protected class members can be denoted in a UML diagram with the __________ symbol.

A) +
B) -
C) *
D) #
Question
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)
Question
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
Question
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.
Question
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) cannot tell
Question
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
Question
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.
Question
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.
Question
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.
Question
If a subclass constructor does not explicitly call a superclass constructor __________.

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
Question
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
Question
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
Question
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
Question
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
Question
When a method is declared with the __________ modifier, it cannot be overridden in a subclass.

A) final
B) super
C) void
D) public
Question
If two methods have the same name but different signatures they are __________.

A) overridden
B) overloaded
C) superclass methods
D) subclass methods
Question
When declaring class data members it is best to declare them as __________.

A) private members
B) public members
C) protected members
D) restricted members
Question
Replacing inadequate superclass methods with more suitable subclass methods is known as __________.

A) method upgrading
B) tactical inheritance
C) method overriding
D) method overloading
Question
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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/64
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Inheritance
1
You can write a super statement that calls a superclass constructor but only in the subclass's constructor.
True
2
Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.
True
3
An abstract class is not instantiated itself but serves as a superclass for other classes.
True
4
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
5
A functional interface is simply an interface that has one abstract method.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
6
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
7
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
8
When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
9
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
10
A __________ member's access is somewhere between public and private.

A) package
B) protected
C) static
D) final
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
12
In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
13
If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
14
If two methods in the same class have the same name but different signatures, the second overrides the first.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
15
It is not possible for a superclass to call a subclass's method.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
16
When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
17
All methods in an abstract class must also be declared abstract.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
18
Every class has a toString method and an equals method inherited from the Object class.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
19
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
20
A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
21
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"
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
22
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
23
Which key word indicates that a class inherits from another class?

A) final
B) super
C) implements
D) extends
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
24
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
25
__________ is a special type of expression used to create an object that implements a functional interface.

A) lambda
B) beta
C) alpha
D) sigma
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
26
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
27
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
28
__________ tells the Java compiler that a method is meant to override a method in the superclass.

A) @Override
B) @Overload
C) @Protected
D) @Inherited
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
29
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
30
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
31
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
32
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
33
The __________ key word is used to call a superclass constructor explicitly.

A) goto
B) this
C) super
D) extends
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
34
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
35
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
36
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
37
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
38
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
39
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
40
All methods specified by an interface are __________.

A) private
B) public
C) protected
D) static
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
41
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) cannot tell
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
42
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
43
A class becomes abstract when you place the __________ key word in the class definition.

A) super
B) extends
C) final
D) abstract
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
44
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
45
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
46
Protected class members can be denoted in a UML diagram with the __________ symbol.

A) +
B) -
C) *
D) #
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
47
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)
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
48
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
49
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
50
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) cannot tell
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
51
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
52
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
53
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
54
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.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
55
If a subclass constructor does not explicitly call a superclass constructor __________.

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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
56
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
57
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
58
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
59
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
60
When a method is declared with the __________ modifier, it cannot be overridden in a subclass.

A) final
B) super
C) void
D) public
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
61
If two methods have the same name but different signatures they are __________.

A) overridden
B) overloaded
C) superclass methods
D) subclass methods
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
62
When declaring class data members it is best to declare them as __________.

A) private members
B) public members
C) protected members
D) restricted members
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
63
Replacing inadequate superclass methods with more suitable subclass methods is known as __________.

A) method upgrading
B) tactical inheritance
C) method overriding
D) method overloading
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
64
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
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 64 flashcards in this deck.