• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Abstracf Vs Interfaces

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When should I go for a abstract class or interface.
Can you please give a real world example
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has been discussed many times before. Use the search tool and you will find previous threads. Or read this thread
[ October 19, 2004: Message edited by: Nigel Browne ]
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raj Joe:
When should I go for a abstract class or interface.
Can you please give a real world example




In an abstract class can define the methods which are common to all child classes but some functions like StartUp & Shutdown may differ from class to class such function's can be writtern inside a abstract class without a definition and the child class is forced to write that function. But in the case of interface none of the methods can have that implementation.

An abstract class can have all the flavours of class members like private public protected, but interface needs to be public in general.

When two unrelated classes need to implement a common properties we can use interface.
Ex: Human , Lorry : both these classes have some common properties like color, Weight.These Color & Weight cannot be in a base class for Class "Human" & Class "Lorry". B'coz if u'r using a base class the classes that extends from this class s'd be logically related to each other.In this case Human & lorry cannot be related logically.

Hope you understood !!!
reply
    Bookmark Topic Watch Topic
  • New Topic