When to use a non-abstract method in an abstract class?

1 answer

Answer

1277695

2026-05-13 16:40

+ Follow

Java
Java

In an abstract class some methods could be abstract meaning a sub-class must provide the actual implementation code or non-abstract in those cases the functionality is common to all or most of the sub-classes. With respect to the non-abstract classes, some sub-classes could override those as needed unless they're defined final.

Example of such classes found in the core J2SE API include:

Java.awt.Component, Java.awt.geom.Point2D, Java.io.InputStream, Java.io.Reader, Java.util.AbstractCollection, and many others.

Take Java.util.AbstractCollection as a typical example. It provides placeholders for abstract methods iterator() and size(), and provides the concrete methods clear(), contains(), isEmpty(), etc. which use the former abstract methods to perform a generic function as defined in the specific implementation of a sub-class. The abstract class defers the details of the specific implementation to its sub-classes. The class Java.util.HashSet extends AbstractCollection and defines the non-abstract implementation code for both iterator() and size() methods.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.