0

Now interface also have some method with body as abstraction class have , then what is the difference in abstraction and interface in java 8 .

Data
  • 58
  • 5
  • 1
    https://www.javaworld.com/article/2139921/learn-java/abstract-class-versus-interface-in-the-jdk-8-era.html – ShadyBears Sep 27 '18 at 05:32
  • 1
    Well you can implement many interfaces, but you can only extend one class. Default methods in interfaces are locked. If you do not define that method, you are locked to the default implementation. With abstract classes, you can define your own implementation and also delegate back to the superclass with super.myMethod() to capture common behavior. – Solace Sep 27 '18 at 05:34

1 Answers1

1

Type of methods: Interface can have only abstract methods. Abstract class can have abstract and non-abstract methods. From Java 8, it can have default and static methods also.

Final Variables: Variables declared in a Java interface are by default final. An abstract class may contain non-final variables.

Type of variables: Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables.

Multiple implementation: An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.

Accessibility of Data Members: Members of a Java interface are public by default. A Java abstract class can have class members like private, protected, etc.

Amit Rai
  • 496
  • 1
  • 4
  • 20