-
extends vs. implements
What's the difference between extends and implements, and when should I use
each...in real world programming of course.
-
Re: extends vs. implements
Mike <mbjohnson59@hotmail.com> wrote in message
news:3944db77$1@news.devx.com...
>
> What's the difference between extends and implements, and when should I
use
> each...in real world programming of course.
"Extends" causes the class to be a new class based on a superclass. Your
class automatically inherits all of the superclass's methods and you can
override any of them (except the ones defined "final") or none of them
(except the ones defined "abstract"), whatever you need.
"Implements" causes the class to be a new class that implements an
interface. Your class MUST override ALL of the interface's methods, because
the interface only has definitions, not code.
For getting started in Java, you'll only need "extends". I've been
programming Java for about a year now and the only use I've found for
"implements" was in Visual Basic, which doesn't allow you to extend a class.
There are places where "implements" makes sense, but only when you have a
concept that's so abstract that it can be implemented in so many ways that
it's better not to try providing base code.
-
Re: extends vs. implements
Hello Mike:
I recently did a DHTML lesson on Inheritance for the Java class that I teach.
You'll need IE4 or later as we've standardized on IE at the school and I
didn't have time to make it cross-browser. Check it out here:
http://www.bright-moments.com/dynamic
If you are running Netscape, much of the same content is available here:
http://www.bright-moments.com/javasite
Just click on Instruction, then choose the lesson on Inheritance
Some of it is a little abstract. I try to teach my students that interfaces
represent a contract between classes to implement the same set of methods.
When beginning to program in Java, many of the interfaces you'll use are
related to event-handling.
Hope this helps,
Tom Duffy
"Mike" <mbjohnson59@hotmail.com> wrote:
>
>What's the difference between extends and implements, and when should I
use
>each...in real world programming of course.
-
Re: extends vs. implements
"Mike" <mbjohnson59@hotmail.com> wrote:
>
>What's the difference between extends and implements, and when should I
use
>each...in real world programming of course.
simply put, extents is used when creating a subclass and implements is used
when implementing an interface. Since java only allows for single inheritance
of superclasses implementing interfaces is a way around this restriction.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks