🚀 Day 7 of "Let's revise the Java with DSA"📚
The interface in Java is a mechanism to achieve abstraction. Traditionally, an interface could only have abstract methods (methods without a body) and public, static, and final variables by default. It is used to achieve abstraction and multiple inheritances in Java. In other words, interfaces primarily define methods that other classes must implement. Java Interface also represents the IS-A relationship.
In Java, the abstract keyword applies only to classes and methods, indicating that they cannot be instantiated directly and must be implemented.
Abstract Class Vs. Interface:
The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class.
->An abstract class can contain both abstract and non-abstract methods whereas Interface contains only abstract methods.
->An abstract class can have all four; static, non-static and final, non-final variables whereas Only final and static variables are used.
->The keyword ‘extend’ is used to extend an abstract class whereas The keyword implement is used to implement the interface.
-> It has class members like private and protected, etc whereas It has class members public by default.
Below figure shows advantages of using Interface.
#20dayschallenge #java #dsa #datastructure #LearningJourney🌟 #day7
Sr FullStack Developer | Flutter | Node.Js | AWS
7moGreat article. A lot of people like to go for the famous terms such as DDD and SOLID without ever understanding the basics of OO and how they affect the implementation of these principles.