Difference between Abstract Class & Interface?

Answer Posted / adikeanand@gmail.com

ABSTRACT CLASS:
1)abstract class contains abstract methods with body and concrete methods also.
2) when a class contains abstract methods declare the class as abstract.
3) when we don't want to allow anybody to create object to the class then declare class as abstract.when we want to use the methods of a abstract class write a class which extends abstract class and create reference variable to abstract class and assign subclass object.
4)We can not create object to the abstract class but we can create reference variable.

INTERFACE:
1)Interface contains abstract methods and static final data.
2)when we are writing a class which implementing interface then we have to provide the body for all the abstract methods of interface.
3)If we don't want to provide all the methods of interface then declare the class as abstract.write the class which extends abstract class and write the methods which you have left abstract methods and create reference variable to interface and assign the object of class which extends abstract class.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is jndi datasource in java?

467


What are jpa annotations?

477


What is meant by swing in java?

448


What is tight coupling in java?

496


Which class is the superclass of every class?

519






What is the resourcebundle class?

534


Why are command line arguments passed as a string?

493


When a thread is created and started, what is its initial state?

549


How do I run a project in eclipse?

443


What are struts java?

486


Why do we only use the main method to start a program?

483


What is a container in java?

469


Is openjdk the same as jdk?

496


What is java flatmap?

484


how can we create the ui using netbeans,having the code?

1623