Prepare for your Next Interview
This is a discussion on difference between abstract class and interface within the Java forums, part of the Software Development category; 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 ...
|
|||
|
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
|
| The Following 2 Users Say Thank You to manipalreddy.s For This Useful Post: | ||
| Sponsored Links |
|
|||
|
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. |
|
|||
|
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. |
| The Following User Says Thank You to vmshenoy For This Useful Post: | ||
|
|||
|
Re: 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... |
|
|||
|
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. |
|
|||
|
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 ![]() |
|
|||
|
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 ![]() |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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.
|
|
|||
|
Quote:
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. |
|
|||
|
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.
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| COM interface | JobHelper | QTP | 1 | 03-30-2007 02:07 PM |
| interface..... | psuresh1982 | Java | 1 | 01-08-2007 01:40 PM |
| Difference between the standard and custom class | JobHelper | WinRunner | 3 | 12-20-2006 05:48 AM |
| how many learners are there in the class? | jamesravid | Brainteasers | 7 | 12-04-2006 07:59 AM |
| Question with Interface | sripri | ASP.NET | 0 | 07-16-2006 12:37 PM |