Inheritance Flashcards
What does a child class inherit from a parent class?
All fields and methods except constructors and final fields
How can a child class create a new instantiation within the abstract parent class?
childConstructor( ){
super( )
}
What is the rule about a child’s constructor calling a parents constructor using “super( )”
It must be the first statement in the child class’s constructor method
If a parent class has constructor with argument but no constructor without argument, and a child class with argument is instantiated does this result in a compilation error?
Usually, unless the child with argument explicitly calls the parent with argument using super(argument)
How can a parent access its child’s fields
It must be casted down to the child
What types of methods cannot be overridden?
private, final or static
where can a public member be accessed from?
within the same class, same package, a child class, or even from a different package
where can a protected member be accessed from?
within the same class, same package, from a child class, NOT from a different package
where can a default member be accessed from?
within the same class and the same package, but NOT from a child class or from a different package
where can a private member be accessed from?
private can be accessed from within the same class only. NOT from within the same package, subclass or an different package
Can abstract classes be instantiated?
No
Can we make a reference variable of an abstract class?
Yes, to instantiate child classes from the parent abstract class
What modifiers to abstract class constructors have?
Protected Modifier
Can abstract classes contain both abstract and non-abstract methods?
Yes
How do you declare an abstract method in an abstract class?
just the header followed by a semicolon
ex: public abstract abstractMethod( );