What is the difference between an interface and an abstract class?

Question

can you please help me with this question

Answer ( 1 )

    • Abstract Class: Can have both abstract (without implementation) and concrete (with implementation) methods. Can have instance variables.
    • Interface: All methods are implicitly abstract (before Java 8). Supports multiple inheritance.
    • Example:
      abstract class Animal {
      abstract void makeSound(); // Abstract method
      void sleep()
      {
      System.out.println("Sleeping"); } // Concrete method

      }
      interface Bird
      {
      void fly(); // Implicitly abstract
      }

Leave an answer