Abstract class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Abstract class

  1. #1
    Manika Guest

    Abstract class


    What is an abstract class?
    Why do we do implements at times and extends at times when writing java servlets?

    What is the difference between these 2?
    Why do we do
    public interface ....
    and
    public class ...

    What does interface and class stand for here?


  2. #2
    spacemadness Guest

    Re: Abstract class


    Whoa dude...you need to read up on some JAVA BASICS. An abstract class in
    defined like this:

    public abstract class MyClass{ }

    It is just like any other class EXCEPT that you can't create objects from
    abstract classes. You can only create objects of it's subclasses which 'extend'
    an abstract class. WHY, have abstract classes? Well, it is used to FORCE
    the programmers that want to use the abstract class to use certain methods
    in the subclasses that wanna extend an abstract class. These methods are
    defined like so, which are inthe abstract class:

    public abstract void myAbstractMethod();

    Just like that...looks strange does it? Where's the { blah; blah; code to
    use in this method?;} (IE it is missing the curly braces) Hehehe well an
    abastract method is NOT used in the abstract class, they are used and DEFINED
    in the subclasses that inheriate them. The subclasses HAVE TO empliment
    ALL abstract methods of an abstract class or you will get a compile error.
    Hence, FORCING a certain code structure. Abstract methods MUST be public
    since all abstract methods in an abstract class that a SUBclass extends MUST
    be implemented, or an error happends.

    implements keyword is related to interfaces. An interface is kinda like
    a very EXTREME abstract class and is defined like so:

    public interface MyCrap(){}

    interface is a CLASS but, no class keyword is used. An interface is like
    an abstract class, except an interface can ONLY have abstract methods. An
    abstract Class can have BOTH regular methods AND abstract methods. You,
    cant instantiate an interface. YOu have to create subclasses (ie implement)
    or (same thing as extend but they decided to make it clear you where extending
    an interface so they called it implements) You like in an abstarct class
    MUST implement ALL the methods in an interface. There fore all methods are
    abstract by default. Think of it as a working template and these parts MUST
    be used in order for a certain operation to work.

    "Manika" <manika@mailexcite.com> wrote:
    >
    >What is an abstract class?
    >Why do we do implements at times and extends at times when writing java

    servlets?
    >
    >What is the difference between these 2?
    >Why do we do
    >public interface ....
    >and
    >public class ...
    >
    >What does interface and class stand for here?
    >



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