NIET
Would you like to react to this message? Create an account in a few clicks or log in to continue.
LATEST NEWS
HI FRIENDS...!








WELCOME TO NIET GALAXY








KEEP VISITING...!








IT IS FOR NIET STUDENTS
FOLLOW ME
JAVA abstract vs interface Twit_05
NOTICE BOARD...!!!
Latest topics
» Beautiful Brides
JAVA abstract vs interface EmptyMon Sep 14, 2009 12:07 pm by NIETGALAXY

» Bollywood actresses In Sarees
JAVA abstract vs interface EmptyMon Sep 14, 2009 12:05 pm by NIETGALAXY

» Childhood photos of Bollywood stars
JAVA abstract vs interface EmptyMon Sep 14, 2009 12:02 pm by NIETGALAXY

» How to Use the Secret
JAVA abstract vs interface EmptySat Sep 05, 2009 1:35 pm by NIETGALAXY

» How to Be A Teacher's Pet
JAVA abstract vs interface EmptySat Sep 05, 2009 1:28 pm by NIETGALAXY

» How to Get into the Habit of Studying for a Test
JAVA abstract vs interface EmptySat Sep 05, 2009 1:24 pm by NIETGALAXY

» Vodafone Free GPRS hack
JAVA abstract vs interface EmptyTue Aug 18, 2009 8:31 pm by anil kumar

» How To Get Big Arms?
JAVA abstract vs interface EmptyTue Aug 18, 2009 8:24 pm by anil kumar

» Airtel GPRS hack
JAVA abstract vs interface EmptyTue Aug 18, 2009 8:20 pm by anil kumar


JAVA abstract vs interface

Go down

JAVA abstract vs interface Empty JAVA abstract vs interface

Post by anil kumar Tue Aug 18, 2009 7:58 pm

Abstract class vs Interface


An abstract class can have shared state or functionality. An interface is only a promise to provide the state or functionality. A good abstract class will reduce the amount of code that has to be rewritten because it's functionality or state can be shared. The interface has no defined information to be shared
In java you can inherit from one (abstract) class to "provide" functionality and you can implement many interfaces to "ensure" functionality

A simple three line concept


Use an abstract class when you want to inherit only from the parent

Use an interface when you want to inherit from multiple sources

Use both when you want a basic behavior from the parent and extra features from other sources

Is there a performance overhead in using either an abstract class or an interface?

Abstract class is faster than interface

we write a program using abstract class in that abstract class
we declare abstract methods and variables.


if we want that methods and variable for another class we
extends that abstract class which method and variable we want

to declare eg: //take an example class shape


abstract class shape
{
int a,b,c;
String s1;
abstract area(int);
abstract area(int a, string s);


}

Here area is used every class ie square, rectangle, triangle
etc.. so which shape we want we extends this abstract. so it
is simple to compare of interface


In interface we declare all methods if not needed that method
that time also we must defined so it will take lot of
time and memory usage




Why we are? and when we are using Interfaces ?

Interfaces are useful when you do not want classes to inherit from unrelated classes just to get the required functionality. For example, let bird be a class with a method fly(). It will be ridiculous for an aeroplane to inherit from bird class just because it has the fly() method. Rather the fly() method should be defined as an interface and both bird and aeroplane should implement that interface.



When should I use an interface instead of an abstract class

Abstract class is an incomplete implementation of some concept. This incomplete implementation may be different in different context. Derived class implements the abstract class in its context.

Interface defines contract or standard. Implementation of the interface has to follow the contract or standard. Interfaces are more used to set these types of standards or contracts.

E.g. In an application there are different editors. There are different toolbars, which can be used on these editors like navigation tool bar. In order to use this tool bar editor should implement that functionality.

So there can be interfaces like - navigation - search – save and modify

if an editor implements all three all toolbars will be enabled. if one then only one will be enable. and implementation of these interface differs from context to context.

In the same example myAbstractEditor can be a class, which implements basic functionality of the editor. Where setting different controls, getting values from them can be abstract, which will depend on editor to editor.
anil kumar
anil kumar

Posts : 9
Join date : 2009-07-23
Location : Piduguralla

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum