Inheritance Flashcards

1
Q

What does a child class inherit from a parent class?

A

All fields and methods except constructors and final fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can a child class create a new instantiation within the abstract parent class?

A

childConstructor( ){
super( )
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the rule about a child’s constructor calling a parents constructor using “super( )”

A

It must be the first statement in the child class’s constructor method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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?

A

Usually, unless the child with argument explicitly calls the parent with argument using super(argument)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can a parent access its child’s fields

A

It must be casted down to the child

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What types of methods cannot be overridden?

A

private, final or static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

where can a public member be accessed from?

A

within the same class, same package, a child class, or even from a different package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

where can a protected member be accessed from?

A

within the same class, same package, from a child class, NOT from a different package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

where can a default member be accessed from?

A

within the same class and the same package, but NOT from a child class or from a different package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

where can a private member be accessed from?

A

private can be accessed from within the same class only. NOT from within the same package, subclass or an different package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can abstract classes be instantiated?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can we make a reference variable of an abstract class?

A

Yes, to instantiate child classes from the parent abstract class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What modifiers to abstract class constructors have?

A

Protected Modifier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can abstract classes contain both abstract and non-abstract methods?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you declare an abstract method in an abstract class?

A

just the header followed by a semicolon
ex: public abstract abstractMethod( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly