Inheritance Flashcards
What is an abstract method?
It is one that describes a behavior but does not implement it.
Can an interface field be declared as private?
No.
Interface fields are always public, static and final.
T/F: Interface fields are always public, static and final.
True, even if not explicitly defined as such.
Can an overriding method change the return type if it is a primitive value?
No.
Can an overriding method change to return type of an Object?
Yes, but only to a subclass of the return type.
This is a covariant return.
Access to static and instance fields and static methods depends on ______ .
the class of the reference variable
T/F: access to static methods and fields depends on the actual object being pointed to
False.
This is the opposite of instance methods.
Will the following code compile?
class Super { } class Sub extends Super { } public class TestClass{ public static void main(String[] args){ Super s1 = new Super(); //1 Sub s2 = new Sub(); //2 s1 = (Super) s2; //3 } }
Yes.
There is no issue here. A sub class can always be assigned to a super class variable without any cast.
T/F: The native keyword can only be used on methods.
True.
Can the native keyword be used on variables.
No.
It can only be used on classes.
Can the default keyword appear for a method in an abstract class?
No.
The default keyword can only occur for a method in an interface.
T/F: Members of an interface (fields and methods) may be abstract.
False.
Can an interface method be default and static?
No.
The default method is always an instance method.
If an interface redeclares a default method, can it provide a different implementation?
Yes.
Can an interface redeclare a default method AND make it abstract?
Yes.