Geeks Talk

Prepare for your Next Interview




difference between abstract class and interface

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 ...


Go Back   Geeks Talk > Software Development > Java

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-17-2007
Junior Member
 
Join Date: Jan 2007
Location: delhi
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
manipalreddy.s is on a distinguished road
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
Reply With Quote
The Following 2 Users Say Thank You to manipalreddy.s For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 01-17-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 8 Times in 7 Posts
vmshenoy is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 01-17-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 8 Times in 7 Posts
vmshenoy is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to vmshenoy For This Useful Post:
  #4 (permalink)  
Old 01-17-2007
Expert Member
 
Join Date: Dec 2006
Location: India
Posts: 140
Thanks: 0
Thanked 6 Times in 4 Posts
nikhil_rattan is on a distinguished road
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...
Reply With Quote
  #5 (permalink)  
Old 01-19-2007
Expert Member
 
Join Date: Oct 2005
Location: india,cochi,bangalore
Posts: 395
Thanks: 2
Thanked 8 Times in 7 Posts
vmshenoy is on a distinguished road
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.
Reply With Quote
  #6 (permalink)  
Old 06-19-2007
Junior Member
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
urs_bluevr is on a distinguished road
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
Reply With Quote
  #7 (permalink)  
Old 10-13-2007
Junior Member
 
Join Date: Jan 2007
Location: moradabad(u.p.),india
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ankur sharma is on a distinguished road
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
Reply With Quote
  #8 (permalink)  
Old 10-14-2007
Junior Member
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
lilkar is on a distinguished road
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
Reply With Quote
  #9 (permalink)  
Old 10-15-2007
Junior Member
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
shankarmu is on a distinguished road
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..
Reply With Quote
  #10 (permalink)  
Old 10-15-2007
Junior Member
 
Join Date: Jan 2007
Location: pune
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
jkpawar is on a distinguished road
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
Reply With Quote
  #11 (permalink)  
Old 10-16-2007
Junior Member
 
Join Date: Oct 2007
Location: INDIA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Mekalakn is on a distinguished road
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.
Reply With Quote
  #12 (permalink)  
Old 10-18-2007
Junior Member
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
prakritiii is on a distinguished road
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.
Reply With Quote
  #13 (permalink)  
Old 10-25-2007
Junior Member
 
Join Date: Feb 2007
Location: delhi
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
neelam_rana1986 is on a distinguished road
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.
Reply With Quote
Reply

  Geeks Talk > Software Development > Java


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 01:23 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved