File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract classes and interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract classes and interface" Watch "Abstract classes and interface" New topic

Abstract classes and interface

ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
can anyone explain me the differences between abstract classes and interfaces and how to use them?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10032


Please post questions here that helps others to read and understand and explain. For know how questions, please refer to K&B. Explaining abstract classes and interfaces would atleast take 30 pages of text and we can't explain it here and also you won't benefit from it. READ THE K&B.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50

I am new to discussion board.So still learning to use the discussion board.Will definitely follow the rules.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

an interface is a contract. the interface definition says "if you want to be what i am, you MUST have these methods with these signiatures".

you then have your class implement the interface. you say "i want to be considered one of those, so I am going to have all those methods".

the beauty of all this is that you can change HOW those methods are implemented as often as you like. Since you are still honoring the contract, nobody gets upset and nothing breaks.

an abstract class is a class that is not entirely defined. it's kind of like 1/2 way between an interface and a class. SOME of the methods might be completly defined and implemented, but at least one is not. So when someone extends from an abstract class, they only have to implement the abstract methods, and they get the rest for free.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
hi fred,

Thanks for your explanation in a simple way.that was a grt help.
I agree. Here's the link:
subject: Abstract classes and interface
It's not a secret anymore!