简体   繁体   中英

Calling Interface or abstract class method through its instance

如果我有一个接口或抽象类MyClass并且它具有方法getInstance() ,则可以通过它(接口或抽象类)执行以下操作。

MyClass obj=MyClass.getInstance();

getInstance seems to be a static method. If it is then you can have static method inside an Abstract class but not inside an Interface. And if your getInstance method returns object of class that is derived from MyClass then you can do that.

If you are using Java 8 then interfaces can have static methods.

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