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



what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

what is difference between abstract and interface? can i give real time example for the two topics?..

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

Post New Answer

More Core Java Interview Questions

Who is the owner of java?

0 Answers  


What is meant by attribute?

0 Answers  


What is floor in java?

0 Answers  


can we have virtual functions in java?

11 Answers   Wipro,


How will you serialize a singleton class without violating singleton pattern?

0 Answers  






What are methods?

0 Answers  


Is it possible to use string in the switch case?

0 Answers  


Explain the available thread states in a high-level?

0 Answers  


Is array a class in java?

0 Answers  


Which is bigger double or float?

0 Answers  


What is string literal in java?

0 Answers  


Can you access non static variable in static context?

0 Answers  


Categories