chapter 10 its
When a subclass overloads a superclass method:
A. Both methods may be called with a subclass object
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
A. ClassA
In an inheritance relationship:
A. The superclass constructor always executes before the subclass constructor
When declaring class data members, it is best to declare them as:
A. private members
Which of the following statements correctly specifies three interfaces?
A. public class ClassA implements Interface1, Interface2, Interface3
Which of the following statements declares Salaried as a subclass of PayType?
A. public class Salaried extends PayType
An abstract class is not instantiated, but serves as a superclass for other classes.
T
Every class has a toString method and an equals method inherited from the Object class.
T
Look at 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 }
c.8
Every class is either directly or indirectly derived from the Object class.
T
It is not possible for a superclass to call a subclass's method.
T
Private members of the superclass cannot be accessed by the subclass.
T
When a subclass extends a superclass, the public members of the superclass become public members of the subclass.
T
Look at 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
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement " + "in the constructor."); } }
A. nothing is wrong with the code
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
F
If two methods in the same class have the same name but different signatures, the second overrides the first.
F
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
When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface.
F
Protected members are:
C. Both A and B
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.
In UML diagrams, inheritance is shown:
A. With a line that has an open arrowhead at one end that points to the superclass
All fields declared in an interface:
A. are final and static
A subclass may call an overridden superclass method by:
A. prefixing its name with the super key word and a dot (.)
Protected class members are denoted in a UML diagram with the symbol
B. #
If ClassC extends ClassB, which extends ClassA, this would be an example of:
B. a chain of inheritance
The super statement that calls the superclass constructor
C. must be the first statement in the subclass's constructor
In an interface all methods have:
C. public access
What key word can you use to call a superclass constructor explicitly?
C. super
All methods in an abstract class must also be declared abstract.
F
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } }
C. The call to the method super must be the first statement in the constructor.
When one object is a specialized version of another object, there is this type of relationship between them.
B. "is a"
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
B. ClassB
Given the following code which of the following is true? public class ClassB implements ClassA{}
B. ClassB must override each method in ClassA
Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); } }
B. It will call the constructor of ClassA That receives an integer as an argument
Look at 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();
B. Line 9
When a method is declared with the ____________ modifier, it cannot be overridden in a subclass.
B. final
If two methods have the same name but different signatures, they are:
B. overloaded
If ClassA extends ClassB, then:
B. public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
If a class contains an abstract method:
B. the method will have only a header, but not a body, and end with a semicolon
In a class hierarchy:
B. the more general classes are toward the top of the tree and the more specialized are toward the bottom.
If a superclass does not have a default constructor or a no-arg constructor:
B. then a class that inherits from it, must call one of the constructors that the superclass does have.
Look at the following code. Which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public final int method1(int a){} Line 5 public double method2(int 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 double method2(double c){} Line 12 }
C. 10
Look at the following code. The method in line ________ will override the method in line __________. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public int method2(int 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 }
C. 10, 4
Like a family tree, a ____________ shows the inheritance relationship between classes.
C. Class hierarchy
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC
C. 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."); } }
C. It will call the constructor of ClassA that receives an integer as an argument
Look at the following code. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(){} 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 as a result of the following statements? ClassA item1 = new ClassC(); item1.method1();
C. Line 14
Replacing inadequate superclass methods with more suitable subclass methods is known as what?
C. Method overriding
Look at 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 }
D. 11
A protected member of a class may be directly accessed by:
D. All of the above
If a subclass constructor does not explicitly call a superclass constructor:
D. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes.
Look at 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 as a result of the following statements? ClassB item1 = new ClassA(); item1.method1();
D. This is an error and will cause the program to crash
Look at 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();
D. This is an error and will cause the program to crash.
If a class contains an abstract method:
D. all of the above
When an "is a" relationship exists between objects, it means that the specialized object has:
D. all the characteristics of the general object, plus additional characteristics.
Look at the following code. The method in line _______ will override the method in line _______. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b, int c){} Line 11 public double method2(double c){} Line 12 }
D. none of the above
A subclass can directly access:
D. only public and protected members of the superclass
If you do not provide an access specifier for a class member, the class member is given ___________ by default.
D. package
Look at the following cod.e 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 }
D.4