Thanks A.jyotsna,
Can u tell me differnce between abstract class and interface
vikash
Answers were Sorted based on User's Feedback
Answer / sridhar
Abstact class can have both concrete and non-concrete
methods where as interface has only non-concrete methods.
Unlike interface, Abstract calss can contain fields that
are not static and final.
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / mohammad shoiab
Difference Between Abstract Classes and Interfaces
Abstraction - A way to provide a view to an object
In real life we have examples like resume,hotel menu,
trailer of a movie as examples for abstraction. They
provide an insight into the other object.
Abstract classes and Interfaces are implementation of
abstraction.
abstract class - when u want to create classification or
hierarchy of classes, u can use inheritance and generally
your parent classes would like to impose certain compulsory
behavior along with some free behaviours. in such a case
the compulsory behavior to be declared as abstract, there
by the class should also be declared as abstract, so the
right place for abstract class is only in the case of
inheritance.
Interface - Interface are more related to roles, like for
example, u r a kind of human, and u r playing the role of a
programmer, here human could be a abstract parent class
and programmer could be a interface.
In real life all roles carry compulsory behaviors and if
you want to get into some role, then it is compulsory to
implement all the methods of the role.
"The world is a stage, every one is a actor, every actor
carries a mask, and when the mask changes the role changes,
and when the role changes the behaviour changes"
The roles are interfaces - u know very well one person can
carry many roles, so one class can carry many interfaces
but it can belong to only one classification. Thats why
multiple inheritance is allowed for interfaces and not
allowed for abstract or concrete classes,
Happy!!! - want to know more fundas - contact me -
Shoiab - 9840135749 - Haaris Infotech - The Java Trainers -
Chennai
Is This Answer Correct ? | 5 Yes | 0 No |
Abstract class:-
1. if we declare ny class as a abstract, then we can't
create an object/instace of that class explicitly.
2.afbstracts class may or may not contain abstract method.
3. if on declare any method as an abstract, then the class
should be declared as abstract.
4.if a method is declared as abstract in abstract class,
then child bound to define the abstract method of parent.
5.abstract class may contain constructor.
6.abstract class may hold the child object.
Interface class:-
1.by default all method be abstract.
2.class can implements more than one interface class.
3.child should give the body of all method of interface
class, but if a child class with abstract keyword, then nod
need to give the body of interface classes method.
4.interface can't create objects but can hold the object of
child.
5. variable in interface class are by default public,
static and final.
6.we can't use the final, static, native,synchronous
keyword with the methods define in interface.
7. we can't declare interface as final.
if any question have, tell me at rkjhaw@sify.com or
info@shandilya.org
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jyotsna gupta
Abstract Class | Interfaces
|
1. Starts with a class keyword | Starts with interface
| keyword
2. abstract modifier has to be | No need to provide abstract
provided | modifier (100 % Abstract)
3. Not necessary to contain | All methods are by default
abstract methods, but if a | public and abstract, and
class has abstract method | all attributes are public
then class has 2 be abstract| static, and final (FIELDS)
4. Used for group of related | Any class can implement
classes only | interfaces
5. Single inheritance is | Multiple inheritance can
allowed only | be achieved
6. All class behaviours are | Cannot have constructors,
allowed, except creating | should initialise its
objects of abstract classes | Fields
Is This Answer Correct ? | 1 Yes | 0 No |
Explain the selection sort algorithm?
Why method overloading and method overriding required in java?
what is difference between method overloading & method overridding with example?
what is the need to set path in java? how many ways to set path in java? Explain breif?
What is the exact difference in between Unicast and Multicast object ?
How will you serialize a singleton class without violating singleton pattern?
What are methods and how are they defined?
List the three steps for creating an object for a class?
How do you join strings in java?
Write a program to find the greatest of three numbers in java?
What is a cup of java?
what is the logic inside any default constuctor?