Interface: In interface just signature of the methods are defined(means abstract meathod). there is no a single method which has body. e.g. void add();
Abstract class: In a abstract class some method are abstract while some are concrete methods. we use abstract keyword when we declare a abstract method. abstract keyword also used to declare class. we cannot creat object of abstract class. we cannot create constructor of abstract class. e.g. abstract class A { Â Â Â abstract void add(); Â Â Â Â void subtract() Â Â Â Â { Â Â Â Â Â Â Â Â Â int a,b; Â Â Â Â Â Â Â Â Â Â a=10, b=5; Â Â Â Â Â Â Â Â Â Â int c=a-b; Â Â Â Â Â Â Â Â Â Â System.out.println(c); Â Â Â Â Â Â } }
Above answer was rated as good by the following members: kottalam, russp
RE:
What is the difference between interface and abstract class
An abstract class may contain code in method bodies which is not allowed in an interface. With abstract classes you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand you can implement multiple interfaces in your class.
RE: What is the difference between interface and abst...
hello
The Main Difference Between the Abstract Class And the Interface are:
1)When inheriting A Interface We have to inherit all the methods of the Interface there's no other option whereas with abstract classes we can inherit the members that we are in need of.
2) The Main difference between these is that Interface cannot have any declaration within it. Just the interface has to have body of the method and the method is to be used by the classes inheriting it. Whereas in the case of Abstract Class it can have declarations (Other than the abstract method) and it can be further extended in the classes inheriting the Abstract Class.
RE: What is the difference between interface and abst...
Abstract Class: A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
Interface: Interfaces like classes define a set of properties methods and events. But unlike classes interfaces do not provide implementation. They are implemented by classes and defined as separate entities from classes
RE: What is the difference between interface and abst...
Abstract Class: (1)it contains both abstract methods and non abstract methods (2) object can't be created just through reference we are calling all the methods (3) it is implemented by subclass i.e which class is extended from this abstract class contains only nonabstract this situation also code will compile fine but problem at runtime abstract can't be declared with Final Synchronized Native just your requirements you implement some methods in the abstract class this class also contain Constructor
Interface contains all abstract methods all methods compulsory implemented by particular class interface does not contain Constructor
RE: What is the difference between interface and abstract class
Interface: In interface just signature of the methods are defined(means abstract meathod). there is no a single method which has body. e.g. void add();
Abstract class: In a abstract class some method are abstract while some are concrete methods. we use abstract keyword when we declare a abstract method. abstract keyword also used to declare class. we cannot creat object of abstract class. we cannot create constructor of abstract class. e.g. abstract class A { abstract void add(); void subtract() { int a b; a 10 b 5; int c a-b; System.out.println(c); } }