简体   繁体   中英

Java instance abstract class, which implements interface

I have interface with two methods and abstract class, which implement this interface and override one method from it. Can I instance this abstract class, without overriding other method of interface? Or can I replace this method with method which have another signature?

UPD: Thanks for answers, I really make mistakes in my question. Can I use anonymus class which will be extend my abstract class, without overriding all methods from implements inrerface? How I understand by answer from DragonK, no, and I need create class, which will be extends abstract class and override others methods?

Can I instance this abstract class

You can never instantiate an abstract class.

You could implement any methods of the interface but you still won't be able to instantiate an abstract class.

Unless you are dealing with Java 8's Default Methods , your interface will have no implementations and thus no methods to override.

In Java, abstract classes cannot be instantiated either, unless you construct an anonymous class .

Can I instance this abstract class, without overriding other method of interface?

  • You can't instantiate an abstract class

can I replace this method with method which have another signature?

  • You can replace this method with method which have another signature. But Classes extend your abstract class will override all abstract method.

You can't instantiate an abstract class. or you can have Anonymous implementation and instantiate the abstract class. while providing overriding abstract method we can can change the "covariant return types" but you cant change the method signature.

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