The Artima Developer Community
Sponsored Link

Java Answers Forum
Interface Vs Abstract classes

1 reply on 1 page. Most recent reply: Nov 29, 2004 12:46 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Parag

Posts: 4
Nickname: ksparag
Registered: Nov, 2004

Interface Vs Abstract classes Posted: Nov 28, 2004 10:27 PM
Reply to this message Reply
Advertisement
Can anybody tell me in Java, exactly in what kind of situation we have to use interface & not an abstract class?
The typical answer is to achieve multiple Inheritance?
But practically is it the only anwer for that?


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Interface Vs Abstract classes Posted: Nov 29, 2004 12:46 AM
Reply to this message Reply
Of course not.

A Interface providec certain functionality without specifying a super class.

A simple example:
I wrote an Interface called Multilangual. It just contains the method setLanguage(String id).

All of my formulas and dialogs and self-made panels implement this method.
So if I change the language during runtime, I know for certain that the method is supported becaucse the objects implement the interface, I don't need to know the class of the objects.

Another Interface I use is the DataHandler for formulas wich have to handle DB data. The methods are gotoNext(), gotoPrevious, restoreData(), saveToDB(), ...

I access the forms through the interface, I can exchange one form with another very easily, because they all implement the same interface.

Flat View: This topic has 1 reply on 1 page
Topic: Import Anomaly Previous Topic   Next Topic Topic: ADT Graph help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use