The Artima Developer Community
Sponsored Link

Java Answers Forum
Difference between Interface and Abstract Classes

3 replies on 1 page. Most recent reply: Jan 15, 2004 9:04 AM by Gb

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
V Vinay

Posts: 1
Nickname: vins
Registered: Dec, 2003

Difference between Interface and Abstract Classes Posted: Dec 11, 2003 8:10 PM
Reply to this message Reply
Advertisement
When is it desired to use Interface and Abstract CLasses.
What will be the scope of the final abstract class
and final abstract methods


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Difference between Interface and Abstract Classes Posted: Dec 11, 2003 10:37 PM
Reply to this message Reply
You seem to be trying to do a SJCP exam and copying pasting questions from some exam paper.

First of all try and read a Certification Book or some resources like www.JavaRanch.com before trying to answer these questions.

Balu

Posts: 3
Nickname: balus
Registered: Jan, 2004

Re: Difference between Interface and Abstract Classes Posted: Jan 9, 2004 2:22 AM
Reply to this message Reply
Well, typically you would use an abstract class in
cases where a functionality needs to be extended. ie,
the sub class is extending something that exists but
is not complete by itself. On the other hand you would
use an interface to enforce a protocol.

One application I have seen of interface is as follows
-
If you had an application that required to do database
transactions with different types of systems (ie.
Oracle, IBM Legacy systems, etc), you could use an
interface to mask the intricacies of connecting with
the various systems from the developer by providing a
common interface to all the systems, while the various
implementations of the interface could have nothing to
do with each other.
In such a case you would have no use for abstract
classes quite simply because it is not a common
functionality that you are extending.

A case for using an abstract class could be for a
banking application where CheckingAccount and
SavingAccount could derive from an abstract
BannkAccount class. Both the sub-classes would derive
some common functionality from the BankAccount class
and them add some of their own, and also BankAccount
would not be complete by itself.

s.balu

Gb

Posts: 2
Nickname: dketch
Registered: Jan, 2004

Re: Difference between Interface and Abstract Classes Posted: Jan 15, 2004 9:04 AM
Reply to this message Reply
> When is it desired to use Interface and Abstract CLasses.
> What will be the scope of the final abstract class
> and final abstract methods

form the book Thinking in Java:
"Choose interfaces over abstract classes. If you know something is going to be a base class, your first choice should be to make it an interface, and only if you’re forced to have method definitions or member variables should you change it to an abstract class. An interface talks about what the client wants to do, while a class tends to focus on (or allow) implementation details"

Flat View: This topic has 3 replies on 1 page
Topic: Java Copilationa nd execution from code Previous Topic   Next Topic Topic: check if input is String?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use