Comp Sci: Java: a bit about abstract classes

Self-tutoring about Java: the tutor mentions a couple of ideas about Java abstract classes.

There are numerous Java versions out there, not all of which necessarily agree on everything. Herein I’m sharing my own experience.

In Java, an abstract class is labeled “abstract” in its definition.

public abstract class Bird{ … }

You can’t instantiate an abstract class. Rather, an abstract class is meant to be extended to one or more non-abstract ones, which can be instantiated.

public class SongSparrow extends Bird{ …. }

Interestingly, however, you can use an abstract class on the left side of an instantiation, with its subclass on the right side:

Bird b = new SongSparrow();

Moreover, you can use an abstract class as a formal parameter:

public void hearSong(Bird the_bird){ … }

When hearSong is called, the actual parameter will be a subclass of Bird.


Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply