Abstract Classes Flashcards

1
Q

What is implementation?

A

Implementing a method refers to defining the functionality of a method within a class. When you implement a method, you provide the code that defines what the method does when it’s called.

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

How do you inherit methods from a superclass?

A

The superclass has methods defined that can be inherited by subclasses.

To do so, use the keyword “extends” after naming the subclass.

Example;
Say you have a superclass called “Animal” which has methods “eat” and “sleep”. These methods simply print out “Animal is sleeping or eating”.

The subclasses are dog and cat with specific methods bark and meow printing dog/cat is barking/meowing respectively.

In the main() method, you can create an instance of the subclasses dog and cat, naming them myCat and myDog.

You can access the methods from the superclass Animal which are eat and sleep. You can access the methods bark from dog and meow from cat. This is inheritance. The methods from Animal are passed down to instances of subclasses dog and cat.

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

Can you create an object or instance of an abstract superclass by calling it an instance of a concrete class?

A

Yes….. The professor, in MainClass01.java, wrote

Product product01 = new Book();

where Book() is a concrete class of the abstract superclass Product.

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

How do you implement abstract methods in a concrete child-class?

A

Since implementations of abstract methods aren’t done in abstract classes, in child-classes, you have to implement them using the @Override annotation.

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