extends vs. implements


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: extends vs. implements

  1. #1
    Mike Guest

    extends vs. implements


    What's the difference between extends and implements, and when should I use
    each...in real world programming of course.

  2. #2
    Paul Clapham Guest

    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.




  3. #3
    Tom Duffy Guest

    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.



  4. #4
    Kevin Casault Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center