Java Interface Rules and Best Practices

📘 Strengthening my knowledge on the 12 Rules of Interface 1️⃣ Interface is a contract 👉 Defines rules that classes must follow ✔ Used for standardization 2️⃣ Cannot create object of interface 👉 Interfaces are incomplete (no full implementation) ❌ new InterfaceName() not allowed 3️⃣ Methods are public & abstract by default 👉 No need to write public abstract ✔ Compiler adds it automatically 4️⃣ Variables are public, static, final 👉 Constant values only ✔ Must be initialized 5️⃣ No constructor in interface 👉 Because object creation is not possible 6️⃣ A class uses implements keyword class A implements InterfaceName 7️⃣ Class must implement all abstract methods 👉 Otherwise class must be declared abstract 8️⃣ Interface supports multiple inheritance 👉 A class can implement multiple interfaces class A implements I1, I2 9️⃣ Interface can extend another interface interface B extends A 🔟 Interface cannot extend a class 👉 Only interfaces can extend interfaces 1️⃣1️⃣ Default methods (JDK 8) 👉 Method with body inside interface ✔ Supports backward compatibility 1️⃣2️⃣ Static methods (JDK 8) 👉 Access using interface name InterfaceName.method() ❌ Not inherited / overridden 🎯 Shortcut Memory Tip 👉 Interface = Contract + Abstract + Constants + JDK8 features #Java #OOP #Interfaces #Programming #Learning #CodingJourney #Developers #TapAcademy

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories