• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract vs interface

 
sarada konda
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract class statisfies all the needs of interface.i.e

interface Test1
{
void method1();
void method2();
......
}
can be replaced with the following abstract calss

abstract class Test{
abstract public void method1();
abstract public void method2();
....
}

so then can any tell me what's the use of interface. thanks in advance
 
Sree Nivas
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go thru the folloing URL:

http://mindprod.com/jgloss/interfacevsabstract.html

Sree Nivas
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and simply use the search function here.

It seems every time a Java course begins at a school somewhere and they get to inheritance half the students post this exact same questions (with slightly different wording) here and in every other Java forum worldwide.
 
louise rochford
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case it helps...

I'd start to design a code solution using interfaces, then change an interface into an abstract class if I could see particular benefits. If an abstract class just as easily be an interface - make it an interface. It'll make your code more reusable / flexible in the future.

Regards, Louise
 
sarada konda
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know the interface has one major adv over abstract class i.e
interface -> a class can implement more than one interface
abstract class -> a class can extend only one abstract class
apart from this is there any major advantage of using interface instead of abstract class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic