Share on Google+Share on Google+

noenoe
Abstract and Interface
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners

What is interface? When time is most suitable for using interface? Why we use interface instead of abstract? What is the differences between abstract and interface?

Ads

View Answers

August 28, 2012 at 12:37 PM


An interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all of the methods defined in the interface

Difference Between Interface and Abstract Class

1)Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.

2)Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.

3)Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..

4)Java interface should be implemented using keyword 'implements'; A Java abstract class should be extended using keyword 'extends'.

5)An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.

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

7)Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.

8)In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.

For more information, visit the following link:

http://www.roseindia.net/help/java/a/interface-vs-abstract-class.shtml










Related Tutorials/Questions & Answers:
Abstract and Interface
Abstract and Interface  what is the difference between Abstract and Interface accurateatly
Abstract and Interface
Abstract and Interface  What is interface? When time is most suitable for using interface? Why we use interface instead of abstract? What is the differences between abstract and interface?   An interface defines a set
Advertisements
Interface vs abstract class
Interface vs abstract class  Hai, Is there any possible to defining abstract methods in Interface
Interface and Abstract class
Interface and Abstract class  Difference between Interface and Abstract class? Give some example   Difference Between Interface and Abstract Class 1)Main difference is methods of a Java interface are implicitly
Interface and Abstract class
Interface and Abstract class  hello,, Can some body tell me what is the difference between an Interface and an Abstract class?   hi, Very Good Question Abstract class is a class which contain one or more abstract
Abstract class and interface in Java
Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between an interface and an abstract class: At the same time multiple interfaces can
Interface Vs Abstract Class
Interface Vs Abstract Class       There are three main differences between an interface and an abstract..., an interface is equivalent to a fully abstract class (a class with only public abstract
abstract class and interface - Java Beginners
? when should we use an abstract class? when should we use interface instead... interface are abstract by default. Abstract method provides the standardization...() { System.out.println ("Moo! Moo!"); } } Why not declare an abstract class as an interface
What are the difference between abstract class and interface?
What are the difference between abstract class and interface?  What are the difference between abstract class and interface
Difference between abstract class and an interface
Difference between abstract class and an interface The difference between abstract class and interface is one of the most popular question in the interview... between abstract class and interface in java. Abstract class is a class
Abstract class and Interface - Java Magazine
Abstract class and Interface  Dear Sir, Please anyone help me........I wane exact difference between Abstract class and Interface.what... abstract class AbstractExample { public AbstractExample(){ System.out.println
Uses of abstract class & interface - Java Beginners
Uses of abstract class & interface  Dear sir, I'm new to java. I knew the basic concepts of interface and the abstract class. But i dont... my doubt Thank you  Hi Friend, Interface: Java does
where exactly we use interface and where abstract class?
where exactly we use interface and where abstract class?  what is the use of interface over abstract class? and where we should use interface and where abstract class
Real Time Example Interface and Abstract Class - Java Beginners
Real Time Example Interface and Abstract Class  Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example
Why does Java provide both abstract class as well as interface
Why does Java provide both abstract class as well as interface  why does java have both abstract class as well as interface? what is the need or importance of having both
Interface
Interface  I need to implement the interface without overriding its method and also don't use abstract class for this. How to do
interface
interface  what the use of interface?   An interface is one which has abstract methods(not defined just declared)and static or non static variables.Any class can implement(inherit)the interface and make use
Interface in java with example
We are going to discuss about Interface in Java. Interface is blueprint of a class. Interface is a collection of abstract methods. Interface has only... all method in interface abstract and public. Multiple inheritance allows
Using Abstract Class
Using Abstract Class          We does not make a object of the abstract class. This class must be inherited. Unlike interface the abstract class may
Interface in JSP
the methods are abstract. There is no code associated with an interface. In an interface all the instance methods are public and abstract. Interfaces are always...Interface in JSP      
Interface
and abstract class   interface ShapeInterface{ int l=0,b=0; public...Interface  1.Create an interface names ShapeInterface that has two methods and one constant and an abstract class named ShapeAbstract that has two
Interface
and abstract class   interface ShapeInterface{ int l=0,b=0; public...Interface  1.Create an interface names ShapeInterface that has two methods and one constant and an abstract class named ShapeAbstract that has two
Interface
for Interface in java? and want to know why they used interface instead of multiple inheritance? Thanks in advance   An interface is one which has abstract... implement(inherit)the interface and make use of the methods(functions
abstract class
abstract class  Can there be an abstract class with no abstract methods
abstract method
abstract method  Can we have abstract class with no abstract methods
abstract method
abstract method  is final method is in abstract class
Abstract class
Abstract class  what is an Abstract class
Abstract class
Abstract class  Can an abstract class be final
interface
interface   what is the use of marking interface
Abstract class,Abstract methods and classes
that have the empty implementation. All the methods in any interface are abstract... Abstract methods and classes     ... so many times the word abstract. In java programming language the word abstract
interface.
interface.  Write short note on interface.   Please visit the following link: Java Interface
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads