3: Quizzes Flashcards
If A “Is-A” B, what else can we say about the relationship between class A and class B?
- Class A extends Class B.
- Class A inherits from Class B.
- Class A derives from Class B.
All 3.
What tool is used to show inheritance or composition relationships among classes.
A class diagram.
Which of the following is a specialized version of a class?
- An ancestor.
- A subclass.
- A superclass.
- class Object.
- class Class
2
Which of the following statements is true?
- Objects never change the class to which they belong.
- In some situations, a variable may be bound to different types of objects.
- The behavior of any object is determined by the object’s class and not by the data type of the variable that references it.
All 3 are true.
Given this start to a class definition:
public class Beta extends Alpha { ... }
What is true about instance variables from Alpha?
- Class Beta must redeclare all of Alpha’s instance variables.
- They should not be redeclared in Beta.
- The Beta class should redeclare only those instance variables from Alpha that it wants.
- Class Beta should redeclare only the private instance variables from Alpha.
2.
If class Fruit is the superclass of class Apple, which of the following is also true?
- Fruit is the base class of Apple
- Fruit is the parent class of Apple
- Apple “Is-A” Fruit
All 3 are true.
If a class definition does not include the keyword extends, which of the following is true?
- The class has no sub class
- The class has no super class
- The class implicitly derives from Class.
- The class implicitly derives from Object.
4.
Which of the following things would prevent a method declaration in a subclass from properly overriding an inherited method?
- not matching the method name
- not matching the return type
- not matching the parameter “signature” (number, order and data types of parameters)
- trying to make a public method private
All of them would prevent a method declaration from properly overriding an inherited method.
What is always the very first thing that occurs in the constructor of a derived class?
A call to the superclass constructor is made.
Which of the following statements creates a composition (or aggregation) relationship?
- public class Fun extends Hun { … }
- return new Fun();
- if ( myThing instanceof Point ) { … }
- private Widget myThing;
4.
Which Java keyword can be used to access the super class version of an overridden method from within the sub class?
super
Given the following code (assume that the statements compile with NO syntax errors):
Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;
What is the static type of ‘top’?
Green
Given the following code (assume that the statements compile with NO syntax errors):
Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;
What is the dynamic type of ‘ocean’ after all the statements have been executed?
Blue
Given the following code (assume that the statements compile with NO syntax errors):
Red hot = new Red(); Green top = hot; Orange ocean = new Blue(); hot = ocean;
What is the dynamic type of ‘hot’ after all the statements have been executed?
Blue
What determines which version of an overridden method is executed?
The dynamic type of the variable that acts as the ‘qualifier’ in the method call.
What determines which version of an overloaded method is executed?
The data types of the arguments of the method call.