Results 1 to 13 of 13

Thread: difference between abstract class and interface

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Answers
    1

    difference between abstract class and interface

    i want to know the difference between abstract class and interface and why we use servlets insntead of cgi .wht is getOnBytes(int size) method,wht is the difference between struts 1.0 and 1.1


  2. #2
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    Re: difference between abstract class and interface

    hi friend

    first i would like to tell you about abstract classes.

    It is a feature of c++. Abstract class means that we cannot create objects of that class. Interface(do mean same) is a concept introduced in java,which is similar to abstract classes.This doesnot mean that java dont have abstract classes.

    Interface means that ALL functions in it have declaration only.no definitioni.e no body.(NOTE: ALL functions)

    Abstract class means even a single function without body/definition is enough in it(to make it abstract)(NOTE:EVEN SINGLE Function is enough to make it abstract)
    therefore 100% pure abstract class is an interface.



    CGI stand for Common gateway interfaces.
    CGI is most general term used to describe programs on the server that provide dynamic content!These programs can be written in C++,perl ,java.

    Servlets is a type of CGI.
    Hope my explanation is clear to you.
    bye


    :)
    NEVER SAY DIE.

  3. #3
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    Re: difference between abstract class and interface

    also do you want to know about getONBytes() !Are you sure? or is it getBytes()

    :)
    NEVER SAY DIE.

  4. #4
    Expert Member
    Join Date
    Dec 2006
    Answers
    139

    Re: difference between abstract class and interface

    Please do not copy and paste from other sites...

    Difference between Abstract class and Interface

    Last edited by admin; 01-19-2007 at 03:04 AM. Reason: Please do not copy and paste from other sites...

  5. #5
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    Re: difference between abstract class and interface

    Thereis one more difference ,which i would like to add .


    Interfaces have an additional capability.A class can implement more than one interface!By contrast , a class can only inherit a single super class(abstract or otherwise)

    bye


    :)
    NEVER SAY DIE.

  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    2

    Thumbs up Re: difference between abstract class and interface

    hi friends,
    abstract class means we can't create the instance for that. It may have all abstract methods(without body), all concrete methods or a mixer of both.

    Interface is special case of abstract class ie., all the methods are abstract methods(without body).

    regards,
    vijayakumar .vr


  7. #7
    Junior Member
    Join Date
    Jan 2007
    Answers
    2

    Re: difference between abstract class and interface

    In Interface we can only declare the methods but can not implement as well as by declaring a method in Interface ,it automatically becomes abstract method.
    And we can only declare the variables but can not initialized in Interface.
    To use the methods and variables we have to implement the interface.


    In Abstract Class we can declare the abstract method as well as normal methods.Diffrence is that we can not implement the abstract method there but implement the normal methods. and abstract method will be Accessible by inherited classes...


    further any confusion then ur most welcome


  8. #8
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    Re: difference between abstract class and interface

    Interface
    Interfaces are implemented
    Interfaces cannot have constructors
    Multiple interfaces can be implemented(thereby allowing multiple inheritance)
    Interfaces can only contain abstract methods or functions
    all the members of an interface are public by default and cannot be explicitly declared so
    All the methods/functions of an interface must be impelmented


    Abstract Class

    Abstract classes are Inherited
    Only a single class can be inherited
    Abstract classes can have both abstract and contrete methods
    All the abstract members of an Abstract Class must be declared public
    All the abstract methods/functions of an Abstract class must be implemented


  9. #9
    Junior Member
    Join Date
    Oct 2007
    Answers
    2

    Re: difference between abstract class and interface

    CGI use separate thread for each and every process.Servlet use same thread for all process.So Servlet is faster one than CGI..


  10. #10
    Junior Member
    Join Date
    Jan 2007
    Answers
    15

    Re: difference between abstract class and interface

    1. in Interface all the methods are public abstract.this is not necessary with abstract class means abstract class can have concrete methods.
    2. all the varible of interface are public static final.this is not necessary with abstract class.
    3.abstract class must be inherited.interface must be extended.


    in CGI for each request one instance is created which consume resouces.
    in Servlet only and only one instance is created by container for servicing many requests.


    thanks


  11. #11
    Junior Member
    Join Date
    Oct 2007
    Answers
    3

    Re: difference between abstract class and interface

    A class implementing an interface must implement all of the methods defined in the interface, while a class extending an abstract class need not implement any of the methods defined in the abstract class. Additionally, a class extending an abstract class can implement an infinite number of it's own methods.


  12. #12
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Smile Re: difference between abstract class and interface

    Quote Originally Posted by manipalreddy.s View Post
    i want to know the difference between abstract class and interface and why we use servlets insntead of cgi .wht is getOnBytes(int size) method,wht is the difference between struts 1.0 and 1.1
    abstract class can have abstract as well as concrete methods whereas an interface can have only abstarct methods.
    interface can have only final and static variables whereas this is not the case with abstract classes.
    also,only subclasses of an abstract class can override its methods whereas in case of an interface any class can do the same.
    In an abstarct class u need to explicitly prefix the method with "abstarct" to show that it is in an abstarct method but this is not the case with interfaces,


    servlets are better as compared to Cgi as CGI is process based which is quite expensive whereas servlets are thread based.and also use less resources as compared to the CGI.
    hope that was helpful.


  13. #13

    Re: difference between abstract class and interface

    The main difference is that an interface is implicitly fully abst class. An interface have all the fields public final static & methods public abstract.All the methods in interface are abstract , you can't provide body to them.While in an abst class it totally depends on you wether you want to have any abst methods or not.


  14.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact