This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Abstracf Vs Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstracf Vs Interfaces" Watch "Abstracf Vs Interfaces" New topic

Abstracf Vs Interfaces

Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
When should I go for a abstract class or interface.
Can you please give a real world example
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
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 ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
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 !!!

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
wood burning stoves
subject: Abstracf Vs Interfaces
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
interface extends interface ?
Home interface or Home Interface stub
Time Capsule
Writing an Interface