Posts

Showing posts with the label Complete Abstraction

Interface in Java: Definition, Rules, and Examples

Interface in Java An interface is a type definition block in Java that is completely abstract. It is used to achieve full abstraction and to define a contract that implementing classes must follow. Key Points An interface is declared using the interface keyword. An interface can contain:            ✓public static final variables (constants)           ✓public abstract methods (instance methods) An interface cannot be instantiated (object creation is not allowed). An interface can extend another interface using the extends keyword. A class can implement an interface using the implements keyword. An interface cannot extend a class. An interface supports complete abstraction because it contains only abstract methods. An interface supports multiple inheritance Example interface Animal {     int AGE = 5; // public static final by default     void sound(); // public abstract by default } class Dog implements Animal { ...