Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2006, 11:11 AM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jimblanc
Default Diffrences of Abstract Classes and Interfaces

I don't know if I could make a new Topic or my problem is already be cleared...
anyway, i think I have problems in understanding Java and one of them is that i don't really feel the difference between Abstract Classes and Interfaces...
Abstract Class has a certain behavior and some methods, abstract of course...
On the other hand Interface inherit specific characteristics.
so what's the difference? because i think that i say the same thing twice...

 
Old September 4th, 2006, 12:47 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai ,

Abstract class in Like Normal Class.But Has some methods which dont have implemntation.Some methods may have implemntation.Also the class is declared as abstract.If a class derived from the abstract class ,the deriving class must provide implemntation for all the abstract base class methods(ie methods without implementation)

But The Interfaces contain purely the prototypes of methods.And Dont Have any Implementation.The deriving class must implemnt all the methods defined in the Interface

 
Old September 4th, 2006, 01:01 PM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jimblanc
Default

i see...and thank you very much...
Also Interface's variables are always public static final ...
only these are the differences? what about inheritance?
the methods in Interfaces can be abstrant?
 
Old September 4th, 2006, 01:23 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai,
FIrst U must understand that meaning of Abstract means 'Not Complete' .The Class can be said complete if it has all methods implemented.So Abstract class cannot be instantiated using 'new' operator.The reason for using abstract class is we can write some generalised class in which some methods dont have implemntation. Now the Responsiblity of implemting the mthods is the one who derives the class.

The Another Main Difference between abstract class and interface is.

1)we can derive abstract class only when it make sense.Our clas smust pass 'is a test' with the base class.
eg. If abstract class is employee ,then we can can write manager class which derives from employee class.Because manager is a employee.
2)Interface can be used to implemented in the completely unrelated classes.



 
Old September 4th, 2006, 01:30 PM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jimblanc
Default

your answers were more than helpful... i always have them in my mind!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract classes/Interfaces vasancer BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 October 22nd, 2008 02:06 PM
polymorphism and abstract classes elvisfeverr C++ Programming 3 October 16th, 2008 01:39 AM
interfaces malli_kv2 Java Basics 1 April 23rd, 2007 05:21 AM
Abstract classes guppyheart C# 1 September 9th, 2003 05:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.