Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is the difference between abstract class and interface in java?

user-image
Question ajoutée par Tanmay Karmakar
Date de publication: 2013/07/28

1.abstract class is a class but interface is not.2.abstract class can have instance methods that implement a default behavior.An Interface can only declare constants and instance methods and all methods are implicitly abstract.3.abstract class allows you to provide a default implementation for some of the methods but an interface does not allow you to provide any implementations.4.abstract class is used to reuse code whereas interface is used for defining a pattern (viz.
contract).5.
interface supports multiple inheritance is used.

interface can contains only  set of abstract methods and static constants.where abstract class contains abstract method and concrete methods.

Venkat Tanneru
par Venkat Tanneru , Android Mobile Application Developer , Younify Applications Pvt ltd

java abstract class can have instance methods that can have a default behaviour andvariables declared in interface are default final

In abstract class have both abstarct and non- abstarct methods.Abstract class don't support multiple inheritance.In abstract class,class name must contain abstract key word.

In interface only have abstarct class.Interface class support multiple inheritance. In interface class,class name must contain interface keyword.

In abstract class , we can achieve zero to hundred percent abstraction, where as in interface we can achieve hundred percent abstraction,

In abstract class , class name must contain abstract key word,

where as in interface class class name must contain interface keyword.

In abstract class we have to write abstract before method to make it abstract, but in interface all the method by default abstract.

abstract is a keyword and when we use abstract with a class then it is called abstract class. if a class decleared as abstract then we can not create object of that class. An abstract class can have abstract and non abstract methods, constructor. An abstract class does not support multiple inheritance. and it may 0% to 100% incomplete.

Where interface is a contract what ideally a class got into and a class is suppose to follow that contract. All the methods in interface by default will be public and abstract (only contain abstract method) and It supports the multiple inheritance. It can contain only static and final variable. and it is 100% incomplete.

Sukhmeet Bhatia
par Sukhmeet Bhatia , Metro Railway Corporation

1. Methods of java interface are abstract and donot have implementations. Abstarct can have partial implementation and can have abstarct and non abstract methods.

2.Interface only have static and final variables . Abstarct class can have non static, non static, final, non final variables

 

BHUSHAN HARKARE
par BHUSHAN HARKARE , DEVELOPER , OMVSAB IT SOLUTION

Methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behaviour. Variables declared in a Java interface is by default final

Mohammad Abrar Abrar
par Mohammad Abrar Abrar , Team Leader , Enkindle Technologies Pvt Ltd

abstract keyword is used to create abstract class whereas interface is the keyword for interfaces.

Abstract classes can have method implementations whereas interfaces can’t.

A class can extend only one abstract class but it can implement multiple interfaces.

We can run abstract class if it has main() method whereas we can’t run an interface.

shafi Mohd Shafi
par shafi Mohd Shafi , Sr.Software developer , Etisalat Telecom

An interface is a contract of methods names to be used in inherited classes where as abstract classes have some methods with or without implementation.where intrafes have all methods without implementation.

Anand Ramangoudra
par Anand Ramangoudra , internship , Rousing designs

Abstract class can have abstract and non-abstract and methods.Abstract class doesn't support multiple inheritance.

Interface can have only abstract methods. Interface supports multiple inheritance.Interface has only static and final variables.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?