Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Abstract classes vs. interfaces

Status
Not open for further replies.

juanferman

Programmer
Nov 14, 2001
40
0
0
US
I just face up this question and I want to check with you guys what is the right answer...

What is the difference beetwing Abstract classes vs. interfaces and a simple sample.

Thanks



===================
::) Juan F. Sarria
 
You can define functions in an abstract class, but you can only define what functions are there in an interface. You can implement several interfaces in a class, but you can only extend one other class, be it abstract or not. That's about it :)

Interfaces are a way to tell a class what it has to implement and define ... its interface to the outside world (what a surprise), while abstract classes are a way to implement part of a classe's behavior, while leaving out several crucial and function-defining parts, therefore crippling the class so it can't be used unless those crucial parts are defined by an extending class.

I hope that was somewhat clear...

Code:
public interface MyInterface
{
  public abstract void doSomething();
  public abstract void doSomethingElse();
}

public abstract class MyAbstractClass
{
  public void doSomething()
  {
    doSomethingElse();
  }
  public abstract void doSomethingElse();
}

haslo@haslo.ch - www.haslo.ch​
 
Thanks a lot haslo :)

===================
::) Juan F. Sarria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top