what is the difference between abstract class and
Interface?where we can use it in realtime projects?

Answer Posted / king alone

1 A class may inplement several interfaces. A class may
extend only one abstract class.
2 An interface can have only abstract methods. An abstract
class can have both abstract methods and concrete methods.
At one abstract method in the abstract class.
3 Interfaces cannot have constructors. Abstract class can
have constructors.
4 Only static final variables are allowed to be decelared.
Both static and instance variables are allowed.
5 All decelared methods are implicitly public. Can have any
kind of methods.
6 We should initialize variables in an interface. Not
necessary to initialize variables in an abstract class.
7 In the case of interface you can make any class in the
hierarchy. In the case of abstract class you know the class
hierarchy in advance.
8 An interface implementation may be added to any existing
third party class. A third party class must be rewritten to
extend only from the abstract class.
9 Interfaces can be implemented by classes that are not
related to one another Abstract classes are used only when
there is a “is-a” type of relationship between the classes.

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it possible to use string in the switch case?

737


How do you remove an element from an arraylist in java?

647


What is the reason behind using constructors and destructors?

775


Explain different ways of creating a thread. Which one would you prefer and why?

781


What super () does in java?

651


What is final?

790


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

736


Does java trim remove newline?

716


Explain parallel processing in java8?

872


What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?

713


What is difference between word and integer?

795


What are the files generated after using IDL to java compiler?

781


What is canonical name in java?

814


What is preparedstatement in java?

770


What are the different types of java?

739