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 |
How many types of literals are there in JAVA?
What does ide stand for?
What is the difference between multiple processes and multiple threads?
What is your platform?s default character encoding and how to know this?
What are generic methods?
My interview asked what is dynamic variable in java and where we use them.
What are synchronized methods and synchronized statements in java programming?
Can any one say how will sort map objects in java?
Can you create an object of an abstract class?
What are the special characters?
what is polymorhism what is inheritance? what is Abstract n Interface? what if two interfaces have same method and a concrete class is implementing both the interfaces. Will there be a compilation error? What are mutable and immutable classes? How can u make a class mutable? when will u use dem ...explain with example? what is overriding and overloading? what is garbage collection? what is Thread? how do dey communicate? what are the different ways of implementing ? have u used any messaging technologies? what is synchronization? what are some additions in java 1.5? what are generics? whst is advanced for loop? what is finally block? can u have a try in finally? yes!! can u have a finally in finally? how do you write junits? when is a object eligible for garbage collection?explain? a = null and b has ref to a will b be eligible to be garbage collected? sql questions like diff joins? how do dey work? exception handling? what is marker interface? what is the need??
11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B”); } 16. } 17. public static void main(String[] args) { 18. new B().process(); 19. } What is the result? 1 B 2 The code runs with no output. 3 Compilation fails because of an error in line 12. 4 Compilation fails because of an error in line 15.