Java-OOPS concepts: What is Interface in Java? When to use interface class?

preview_player
Показать описание
#coreJava #Interface #seleniumWithJava
+ What is Interface in Java?
+ When to use interface class?
▬▬▬▬▬▬ In this Video ▶️ ▬▬▬▬▬▬
Interface:
 Interface is nothing but the pure abstract class which contains only abstract method
 All methods are default abstract. Means no body definition. Ex: iTestListener
 Unable to create an object of interface class.
 Unable to use 'final' keyword in interface methods as final will not allow to override but interface needs to override all its methods after implements to child class.
 In order to declare an interface the keyword “interface” is used.
Ex: public interface MyInterface{ }
 Use implements keyword to inherit interface to child class.

Q: when to use interface class?
A: Since java doesn't allow multiple inheritance in case of concrete class, but using interface it can achieve multiple inheritance.
Interface means set of public methods without body that needs to implement through a sub class. Means when we need specifies set of methods in design without definition so that implementation can be different to each sub-class based on our requirement.
Ex: WebDriver, iTestListener

▬▬▬▬▬▬ Useful Links 🛠 ▬▬▬▬▬▬

▬▬▬▬▬▬ Connect with us 👋 ▬▬▬▬▬▬
📱 Twitter: / codenboxteam

🌟 Please hit on LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
Рекомендации по теме
Комментарии
Автор

Thanks a lot. You explained very easy way. Appreciate it.

parveentaher