unit 9 Flashcards
t/f: all getter methods have return types of void
false, though true for setter methods
what does the capital E stand for in the java quick reference?
object type
overridden method
subclass has same method name AND parameter list, but method does not call exact same thing as in parent class
when is super NOT super.?
in the constructor, just super()
what do you inherit?
everything PUBLIC
does return type matter in overloading?
nah
true/false: super must always be the first statement in a constructor
true
does the statement compile:
Statue eTanseer = new Gargoyle(“eshan”);
where gargoyle is a subclass of statue?
ye
when is super() implemented?
- in a constructor, when you have private variables/fields in the superclass which you want to initialize
- automatically/implicity, when a class has a parent class
what happens if super is not explicitly called and the superclass has no no-args constuctor?
compile error
are constructors inherited?
NO, thats why we use super and java calls super if you dont
when is super called automatically/invisibly?
ONLY in constructors
in the body of a class you have access to….
all the fields within that class
to override an object method…
you must use type Object as a parameter
same thing with anything else being overriden, must have same object as for method being overriden (i think?)
what is an abstract class
a class that cannot and should not be instantiated (think pet, cant create a pet w/o subclass)
what happens when you declare a subclass object as the type of a superclass?
ex.
statue Eshan = new Gargoyle();
annotate your questions with arrows showing left to right or right to left and columns and rows and such
why dont subclasses inherit constructors, even though theyre public?
because it must have the same header, and as theyre different classes and constructors are based on class headers, they literally cant have the same constructor header
when does java create an automatic no args constructor?
ONLY when the superclass/class DOES NOT ALREADY have a constructor
How to override method
To override an inherited method, the method in the child class must have the same name, parameter list, and return type (or a subclass of the return type) as the parent method. Any method that is called must be defined within its own class or its superclass.
if a inherits from b, b inherits crom c, and c inherits from d, check ANY that are true
1. a is the grandparent of b, c, and d
2. d is derived from b
3. b may use public methods that are declared in c
4. c may use public methods that are declared in a
5. a may use public meths that are declared in d
3 and 5