• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Abstract and Interface

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Plz. Could anybody tell me about the difference between Abstract and Interface Class and also i want to know what is the use of Abstract class?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract classes r used when u want to make sure that their is a method that the subclass has to inherit and it does not a means to provide multiple inheritence but interfaces r used for multiple inheritence.
also u can make a reference of interface but not of any abstract class.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, the only real differences I see between abstract classes and interfaces are A) you have to implement an interface, where as an abstract class is extended and B) an abstract class can contain methods with implementations, where as an interface can not and C) you can only extend one class, but you can implement any number of interfaces. While interfaces are Java's answer to multiple inheritance, it does not function quite the same way.
I can have the following code:
And I'll get "Foo!" printed out. I get the exact same response if I have this code:
The two abstract and interface classes act the same way here. However, I could add another method to the abstract Foo class, and give it an implementation, but could not do the same to the interface Foo, the compiler would give an error. Preferably, I would use the interface version over the abstract, since you only get to extend one class. The only time you would want to use abstract (correct me if I am wrong here) classes is if that class also needed some of its own implementation, or just to make the design make sense (an abstract Animal class probably wouldn't be a logical interface).
Hope that helps
Jason
[This message has been edited by jason adam (edited November 01, 2001).]
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic