0% found this document useful (0 votes)
4 views1 page

Abstract Class vs Interface in Java

Java interfaces have methods that are implicitly abstract and cannot have implementations, while abstract classes can have instance methods with default behavior. Interfaces have final variables and public members by default, whereas abstract classes can have non-final variables and various access modifiers. A class can implement multiple interfaces but can only extend one abstract class, and interfaces are generally slower due to additional indirection.

Uploaded by

Avinash Kumawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Abstract Class vs Interface in Java

Java interfaces have methods that are implicitly abstract and cannot have implementations, while abstract classes can have instance methods with default behavior. Interfaces have final variables and public members by default, whereas abstract classes can have non-final variables and various access modifiers. A class can implement multiple interfaces but can only extend one abstract class, and interfaces are generally slower due to additional indirection.

Uploaded by

Avinash Kumawat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Main difference is methods of a Java interface are implicitly abstract and c annot have implementations.

A Java abstract class can have instance methods that implements a default behavior. Variables declared in a Java interface is by default final. An abstract cla ss may contain non-final variables. Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members li e private, protected, etc.. Java interface should be implemented using eyword implements ; A Java abstract class should be extended using eyword extends . An interface can extend another Java interface only, an abstract class can e xtend another Java class and implement multiple Java interfaces. A Java class can implement multiple interfaces but it can extend only one ab stract class. Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invo ed if a main() exists. In comparison with java abstract classes, java interfaces are slow as it req uires extra indirection.

You might also like