Prepare for your Next Interview
This is a discussion on Diff B/W Interface & Abstract class within the Java forums, part of the Software Development category; Hi frnds, Can any body solve my qustion, In Interface containing abstract methods right...... and Abstract class also containing abstract methods right.... so both are using abstract methods. Then why ...
|
|||
|
Hi frnds,
Can any body solve my qustion, In Interface containing abstract methods right...... and Abstract class also containing abstract methods right.... so both are using abstract methods. Then why Interface or Abstract class ?????? what's the diff Let me know at least 3 resons plz... Thanks & Regards, Sreekanth S. Last edited by sforsree : 02-25-2008 at 03:45 AM. |
| The Following User Says Thank You to sforsree For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: Diff B/W Interface & Abstract class
Diff B\w Interface And abstract Class:
1.Abstract class contains abstract method but interface did't contains abstact method 2.modifier for abstact class can be public and internal for interface modifier can be public and abstacr 3.it's an incompleate class but interface is not a class it is treated as class for abstact class keyword abstact is used but for inteface , keyword interface is used . i think so it will be helpful for u . thanks G.S.Rathore |
| The Following User Says Thank You to gyanrathore3438 For This Useful Post: | ||
|
|||
|
Re: Diff B/W Interface & Abstract class
Hi Rathore,
Thanks for your give advise. But I have one doubt, when you says interface did't contains abstract method , but in Interface by default all methods are public abstract. Is it right or wrong. plz solve this doubt. Thanks & Regards, Sreekanth S Quote:
|
|
|||
|
Re: Diff B/W Interface & Abstract class
In abstract class there is no necessity that, all the methods should be abstract. there can be both abstract and concrete methods.
But in interface all the methods are abstract. No method should be concrete. |
|
|||
|
Re: Diff B/W Interface & Abstract class
Hi Sree,
Abstract class and interfaces are completely different. 1) In an abstract class, you may also have some concrete methods( fully implemented. It can have all its methods as concrete, yet be declared as abstract) , but in an interface, all the methods ought to be abstract. 2)Abstarct class can never be instantiated, but you can indirectly instantiate an interface by instantiating the class which implements it and then use the its methods. |
|
|||
|
Re: Diff B/W Interface & Abstract class
Abstract classes are intended to be used base class. An abstract class cannot be instantiated.
A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors. Abstract and sealed (class cannot be inherited) modifier can’t work together. An abstract class can have abstract members as well non-abstract members. But in an interface all the members are implicitly abstract and all the members of the interface must override to its derived class. Abstract classes can have protected members, static members. The members of the interface are public with no implementation An interface can inherit from one or more base interfaces. A class can inherit one or more interfaces, but only one abstract class. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Difference between interface and abstract class? are they both same | mahesh9920 | OOPS | 17 | 1 Week Ago 02:44 AM |
| Real time example for abstract class and interface | Geek_Guest | Java | 2 | 01-31-2008 01:50 PM |
| difference between abstract class and interface | manipalreddy.s | Java | 12 | 10-25-2007 07:06 AM |
| Is there any benefit to extend both Interface and abstract class | Geek_Guest | Java | 1 | 06-08-2007 01:54 PM |
| Confusion with ABSTRACT and INTERFACE | Geek_Guest | Java | 2 | 05-07-2007 04:38 AM |