what is difference between abstract and interface?
can i give real time example for the two topics?
Answers were Sorted based on User's Feedback
Answer / pawan v. tak
abstract class cantains implemented as well as non
implemented methods.The non implemented methods are called
as abstract methods.if we do not provide the
implementations of all the methods of the abstract class
the class that extends this class should be declared as
abstract.
And interface contains only abstract methods, i.e no method
implementaion is there in interface.In interface all data
members are public final and static means they wont be
changed and can be called by using classname and "."
operator. If you need to change your design, make it an
interface.
Is This Answer Correct ? | 17 Yes | 4 No |
Answer / madhu samala
abstract is a keyword which can be applied to a class or a
class method. When we declare a class as an abstract one,
it may contain the abstract methods. Abstract method is a
method which contains only the declaration but not the
definition (body). The body for this method will be
provided in it's derived classes.
Note: An abstract class may not contain any abstract
method, but if it contains it must be declared as an
abstract class.
An interface is a contract. The contract will be between
the interface and the class.
An interface only contains abstract methods.i.e. They
contain only the method definition not the body.
The body for these methods must be provided inside the
class which implements that interface. If it doesn't
provide then it has to be declared as abstract.
Is This Answer Correct ? | 12 Yes | 0 No |
Answer / tharun raj s
an abstract class contains 1)instance variables 2)concrete
methods(implemented methods). 3)abstract
methods(unimplemented methods)
An interface contains 1)abstract methods and variables which
are public static and final by default
Abstract class is written when there are certain common
features shared by all the objects
Interface is written when all the features are implemented
differently in different objects
when an abstract class is written it is the duty of the
programmer to provide subclasses to it.
An interface is written when the programmer wants to leave
the implementation to the third party vendors
Is This Answer Correct ? | 11 Yes | 1 No |
Answer / mahesh yadav ch
interface is a abstract, but abstract is not a interface.
interface is fully-unimplemented structure. where as
abstract is partly implement or may not implement structure.
interface contains statements only(public static final int
a;public void f1();).but abstract contains abstract methods
& variables
Is This Answer Correct ? | 12 Yes | 5 No |
Answer / srinu
interface:interface contain only undefined methods
Abstract: Abstract class contain some undefined methods 0r
some defined methods or all defined methods.
Ex: Real time Example
interface Father
{
public void studyDaily();
public void dailyGotoCollege();
}
Abstrct class Son implements Father
{
public Void studyDaily();---->But his son didnot Study
daily he does n't interet Daily
public void dailyGotoCollege()
{
System.out.println("yes Father I go to college");
}
}
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / richa
abstract class can have some concrete methods and abstract
methods too.abstract class can use accessibility modifier
in abstract class.
but in interface all the method are abstract.In interface
no accessibility modifier is allowed by default it takes
public access modifier.
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / lakshmi
Interface has no implementation, but they have to be
implemented.
Abstract class’s methods can have implementations and they
have to be extended.
Interfaces can only have method declaration (implicitly
public and abstract) and fields (implicitly public static)
Abstract class’s methods can’t have implementation only
when declared abstract.
Interface can inherit more than one interfaces
Abstract class can implement more than one interfaces, but
can inherit only one class
Abstract class must override all abstract method and may
override virtual methods
Interface can be used when the implementation is changing
Abstract class can be used to provide some default behavior
for a base class.
Interface makes implementation interchangeable
Interface increase security by hiding the implementation
Abstract class can be used when implementing framework
Abstract classes are an excellent way to create planned
inheritance hierarchies and also to use as non-leaf classes
in class hierarchies.
Is This Answer Correct ? | 0 Yes | 2 No |
What is the difference between yield() and sleep()?
What is the difference between final, finally and finalize()?
What is difference between stringbuffer and string?
what is multitherading
Is minecraft 1.15 out?
What is the immediate parent class of the Applet class?
What is subsequence of a string?
Define inheritance with reference to java.
What is a databasemetadata?
How do you get the length of a string in java?
What are desktop procedures?
What is clipping?