Deck 11: Inheritance

Full screen (f)
exit full mode
Question
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 }

A) 4
B) 5
C) 10
D) 11
Use Space or
up arrow
down arrow
to flip the card.
Question
Look at 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) 1
B) 2
C) 3
D) 4
Question
When an "is a" relationship exists between objects,it means that the specialized object has

A) some of the characteristics of the general class,but not all,plus additional characteristics.
B) some of the characteristics of the general object,but not all.
C) none of the characteristics of the general object.
D) all the characteristics of the general object,plus additional characteristics.
Question
All fields declared in an interface

A) are final and static
B) have protected access
C) must be initialized in the class implementing the interface
D) have private access
Question
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();

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 the 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
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 }

A) 6
B) 7
C) 8
D) 9
Question
Which of the following statements declares Salaried as a subclass of PayType?

A) public class Salaried extends PayType
B) public class Salaried implements PayType
C) public class Salaried derivedFrom(Paytype)
D) public class PayType derives Salaried
Question
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 }

A) 10,4
B) 11,5
C) Both a and b
D) None of the above
Question
Given the following code which of the following 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
If you do not provide an access specifier for a class member,the class member is given ___________ by default.

A) private
B) public
C) protected
D) package
Question
If a class contains an abstract method,

A) you cannot create an instance of the class
B) the method will have only a header,but not a body,and end with a semicolon
C) the method must be overridden in subclasses
D) All of the above
Question
In UML diagrams,inheritance is shown

A) With a line that has an open arrowhead at one end that points to the superclass
B) With a line that has an open arrowhead at one end that points to the subclass
C) With a line that has a closed arrowhead at one end that points to the superclass
D) With a line that has a closed arrowhead at one end that points to the subclass
Question
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();

A) Line 4
B) Line 9
C) Line 14
D) This is an error and will cause the program to crash
Question
Look at the following code and determine what the call to super will do. public class ClassB extends ClassA
{
Public ClassB()
{
Super(10);
}
}

A) This cannot be determined form the code shown.
B) It will call the constructor of ClassA that receives an integer as an argument.
C) It will call the method named super and pass the value 10 to it as an argument.
D) The method super will have to be defined before we can say what will happen.
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
If ClassC extends ClassB,which extends ClassA,this would be an example of

A) multiple inheritance.
B) a chain of inheritance.
C) a family tree.
D) packaging.
Question
If ClassA extends ClassB,then

A) public and private members of ClassB are public and private,respectively,in ClassA
B) public members in ClassB are public in ClassA,but private members in ClassB cannot be directly accessed in ClassA
C) neither public or private members in ClassB can be directly accessed in ClassA
D) private members in ClassB are changed to protected members in ClassA
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
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) All of the above.
Question
If a class contains an abstract method,

A) you must create an instance of the class
B) the method will have only a header,but not a body,and end with a semicolon
C) the method cannot be overridden in subclasses
D) All of the above.
Question
When one object is a specialized version of another object,there is this type of relationship between them.

A) "has a"
B) "is a"
C) direct
D) "contains a"
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
In an interface all methods have

A) private access
B) protected access
C) public access
D) packaged access
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
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
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 }

A) 4,10
B) 5,11
C) 10,4
D) 11,5
E) Both a and b
Question
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
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
In the following statement,which is the interface? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) Cannot tell
Question
Protected class members are denoted in a UML diagram with the symbol

A) *
B) #
C) +
D) -
Question
In a class hierachy

A) the more general classes are toward the bottom of the tree and the more specialized are toward the top.
B) the more general classes are toward the top of the tree and the more specialized are toward the bottom.
C) the more general classes are toward the left of the tree and the more specialized are toward the right.
D) the more general classes are toward the right of the tree and the more specialized are toward the left.
Question
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.
B) It does not have a constructor.
C) It does not overload methodA.
D) Nothing is missing.It is a complete class.
Question
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 }

A) 4
B) 5
C) 10
D) 11
Question
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();

A) Line 4
B) Line 9
C) Line 14
D) This is an error and will cause the program to crash.
Question
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();

A) Line 4
B) Line 9
C) Line 14
D) This is an error and will cause the program to crash.
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 form 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
Which of the following statements correctly specifies three interfaces:

A) public class ClassA implements Interface1,Interface2,Interface3
B) public class ClassA implements [Interface1,Interface2,Interface3]
C) public class ClassA implements (Interface1,Interface2,Interface3)
D) public class ClassA implements Interface1 Interface2 Interface3
Question
A subclass can directly access

A) all members of the superclass
B) only public and private members of the superclass
C) only protected and private members of the superclass
D) only public and protected members of the superclass
Question
Protected members are

A) not quite private
B) not quite public
C) Both A and B
D) Neither A or B
Question
If a superclass does not have a default constructor or a no-arg constructor,

A) then a class that inherits from it,must initialize the superclass values.
B) then a class that inherits from it,must call one of the constructors that the superclass does have.
C) then a class that inherits from it,does not inherit the data member fields from the superclass.
D) then a class that inherits from it,must contain the default constructor for the superclass.
Question
In an inheritance relationship,the subclass constructor always executes before the superclass constructor.
Question
Every class has a toString method and an equals method inherited from the Object class.
Question
Every class is either directly or indirectly derived from the Object class.
Question
An abstract class is not instantiated,but serves as a superclass for other classes.
Question
All methods in an abstract class must also be declared abstract.
Question
If a method in a subclass has the same signature as a method in the superclass,the subclass method overloads 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 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.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/49
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Inheritance
1
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 }

A) 4
B) 5
C) 10
D) 11
C
2
Look at 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) 1
B) 2
C) 3
D) 4
D
3
When an "is a" relationship exists between objects,it means that the specialized object has

A) some of the characteristics of the general class,but not all,plus additional characteristics.
B) some of the characteristics of the general object,but not all.
C) none of the characteristics of the general object.
D) all the characteristics of the general object,plus additional characteristics.
D
4
All fields declared in an interface

A) are final and static
B) have protected access
C) must be initialized in the class implementing the interface
D) have private access
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
5
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();

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 49 flashcards in this deck.
Unlock Deck
k this deck
6
What is wrong with the following code? public class ClassB extends ClassA
{
Public ClassB()
{
Int init = 10;
Super(40);
}
}

A) Nothing is wrong with the 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 49 flashcards in this deck.
Unlock Deck
k this deck
7
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 }

A) 6
B) 7
C) 8
D) 9
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following statements declares Salaried as a subclass of PayType?

A) public class Salaried extends PayType
B) public class Salaried implements PayType
C) public class Salaried derivedFrom(Paytype)
D) public class PayType derives Salaried
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
9
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 }

A) 10,4
B) 11,5
C) Both a and b
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
10
Given the following code which of the following 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 49 flashcards in this deck.
Unlock Deck
k this deck
11
If you do not provide an access specifier for a class member,the class member is given ___________ by default.

A) private
B) public
C) protected
D) package
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
12
If a class contains an abstract method,

A) you cannot create an instance of the class
B) the method will have only a header,but not a body,and end with a semicolon
C) the method must be overridden in subclasses
D) All of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
13
In UML diagrams,inheritance is shown

A) With a line that has an open arrowhead at one end that points to the superclass
B) With a line that has an open arrowhead at one end that points to the subclass
C) With a line that has a closed arrowhead at one end that points to the superclass
D) With a line that has a closed arrowhead at one end that points to the subclass
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
14
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();

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 49 flashcards in this deck.
Unlock Deck
k this deck
15
Look at the following code and determine what the call to super will do. public class ClassB extends ClassA
{
Public ClassB()
{
Super(10);
}
}

A) This cannot be determined form the code shown.
B) It will call the constructor of ClassA that receives an integer as an argument.
C) It will call the method named super and pass the value 10 to it 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 49 flashcards in this deck.
Unlock Deck
k this deck
16
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 49 flashcards in this deck.
Unlock Deck
k this deck
17
If ClassC extends ClassB,which extends ClassA,this would be an example of

A) multiple inheritance.
B) a chain of inheritance.
C) a family tree.
D) packaging.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
18
If ClassA extends ClassB,then

A) public and private members of ClassB are public and private,respectively,in ClassA
B) public members in ClassB are public in ClassA,but private members in ClassB cannot be directly accessed in ClassA
C) neither public or private members in ClassB can be directly accessed in ClassA
D) private members in ClassB are changed to protected members in ClassA
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
19
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 49 flashcards in this deck.
Unlock Deck
k this deck
20
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) All of the above.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
21
If a class contains an abstract method,

A) you must create an instance of the class
B) the method will have only a header,but not a body,and end with a semicolon
C) the method cannot be overridden in subclasses
D) All of the above.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
22
When one object is a specialized version of another object,there is this type of relationship between them.

A) "has a"
B) "is a"
C) direct
D) "contains a"
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
23
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 49 flashcards in this deck.
Unlock Deck
k this deck
24
In an interface all methods have

A) private access
B) protected access
C) public access
D) packaged access
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
25
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 49 flashcards in this deck.
Unlock Deck
k this deck
26
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 49 flashcards in this deck.
Unlock Deck
k this deck
27
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 }

A) 4,10
B) 5,11
C) 10,4
D) 11,5
E) Both a and b
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
28
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
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 49 flashcards in this deck.
Unlock Deck
k this deck
29
In the following statement,which is the interface? public class ClassA extends ClassB implements ClassC

A) ClassA
B) ClassB
C) ClassC
D) Cannot tell
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
30
Protected class members are denoted in a UML diagram with the symbol

A) *
B) #
C) +
D) -
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
31
In a class hierachy

A) the more general classes are toward the bottom of the tree and the more specialized are toward the top.
B) the more general classes are toward the top of the tree and the more specialized are toward the bottom.
C) the more general classes are toward the left of the tree and the more specialized are toward the right.
D) the more general classes are toward the right of the tree and the more specialized are toward the left.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
32
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.
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 49 flashcards in this deck.
Unlock Deck
k this deck
33
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 }

A) 4
B) 5
C) 10
D) 11
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
34
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();

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 49 flashcards in this deck.
Unlock Deck
k this deck
35
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();

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 49 flashcards in this deck.
Unlock Deck
k this deck
36
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 form 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 49 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following statements correctly specifies three interfaces:

A) public class ClassA implements Interface1,Interface2,Interface3
B) public class ClassA implements [Interface1,Interface2,Interface3]
C) public class ClassA implements (Interface1,Interface2,Interface3)
D) public class ClassA implements Interface1 Interface2 Interface3
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
38
A subclass can directly access

A) all members of the superclass
B) only public and private members of the superclass
C) only protected and private members of the superclass
D) only public and protected members of the superclass
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
39
Protected members are

A) not quite private
B) not quite public
C) Both A and B
D) Neither A or B
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
40
If a superclass does not have a default constructor or a no-arg constructor,

A) then a class that inherits from it,must initialize the superclass values.
B) then a class that inherits from it,must call one of the constructors that the superclass does have.
C) then a class that inherits from it,does not inherit the data member fields from the superclass.
D) then a class that inherits from it,must contain the default constructor for the superclass.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
41
In an inheritance relationship,the subclass constructor always executes before the superclass constructor.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
42
Every class has a toString method and an equals method inherited from the Object class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
43
Every class is either directly or indirectly derived from the Object class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
44
An abstract class is not instantiated,but serves as a superclass for other classes.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
45
All methods in an abstract class must also be declared abstract.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
46
If a method in a subclass has the same signature as a method in the superclass,the subclass method overloads the superclass method.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
47
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 49 flashcards in this deck.
Unlock Deck
k this deck
48
It is not possible for a superclass to call a subclass's method.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
49
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.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 49 flashcards in this deck.