简体   繁体   中英

Abstract class derived from concrete class

I've just got a warning in my IDE that my class is abstract but it is derived from concrete class. And what? Why can't I do so? This suites my needs very well. It's just a warning though so the class is compilable. Just interested why it gives me this warning. Thank you.

Update

I need to extend my question with some explanations. I have this class derived from other class and I want nobody to be able to instantiate it. Moreover, I need two subclasses from this abstract class and each of them to have their own implementation of one abstract method. That's why.

Do you think it is bad idea? What approach shall I take instead?

I think the reason is maybe that abstract classes usually serve for basic behavior/information for creating subclasses. Think about other programmers while making such a decision. Others don't expect it.

Anyway, you can set compiler preferences not to give warnings for this type of "problem".

Update

After reading your update I think the simplest way is to declare this class's constructor protected . For the abstract method: you can simply override that from your subclasses, I think.

You can do that. That's why you got a warning and not an error.

This is a common case and typically points to bad system architecture. That's why the compiler shows a warning.

Java compiler warnings are just an indication to the programmer that shouldn't be done normally otherwise the programmer may get bugs due to it in future.

See this link as it explains why to bother about warnings

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