Digging into JAVA — Chapter 08
Hello everyone, Today I am going to talk about “Interfaces and Abstract classes”.
Abstract class: An abstract class indicates that no new instances of that class may ever be created. We may still use that abstract class as a stated reference type for polymorphism, but we don’t have to worry about anyone creating instances of that type. It is guaranteed by the compiler.
Unless it is expanded, an abstract class has almost no utility, value, or purpose in life. The men performing the job at runtime with an abstract class are instances of a subclass of your abstract class.
Abstract and Concrete Classes: A concrete class is one that is not abstract. We only instantiate a specific subclass of Component, never the Component itself.
Abstract methods: An abstract class indicates that the class must be expanded, whereas an abstract method indicates that the method must be overridden. The abstract technique, in particular, lacks a body. As a result, we avoided using curly brackets and simply ended the declaration with a semicolon. If we include even one abstract method in a class, we must make the class abstract. However, in the abstract class, we can mix abstract and non-abstract methods. Abstract methods lack a body and exist merely to support polymorphism. That is, all abstract methods must be implemented by the first concrete class in the inheritance tree.
Interface: Interface is a completely abstract class. A Java interface addresses your many inheritance dilemmas by providing many of the polymorphic benefits of multiple inheritances while eliminating the anguish and suffering caused by the Deadly Diamond of Death.
That’s it from this story. Have a nice day! 👋
Head First JAVA — Second Edition by Kathy Sierra, and Bert Bates.