简体   繁体   中英

What is the use of an empty abstract class?

I want to know that is there any use of empty abstract class in Java? If so, what is it?

An empty abstract class is very much equivalent to an interface except that it can extend a class

abstract class myAbstractClass // extends anotherClass implements anInterface
{

}

interface myInterface // extends anotherInterface
{

}

This pattern is called Marker interface and SO has a lot of good data about it already: What is the purpose of a marker interface?

you can only inherit from one abstract class. Then this is useful to avoid inheritance.

是的,有时你需要一个实现多态的基类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM