answersLogoWhite

0


Best Answer

Differences:

  1. Abstract class can also contain method definitions but an interface can contain only declarations
  2. All variables in an interface are by default public static and final whereas in Abstract class it is not

An interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Some differences are:

  • An abstract class can have code for one or more methods but an interface cannot
  • All variables in an interface are public static and final but in an abstract class it is not
  • Abstract classes are faster than interfaces
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is difference between abstract class and interface in core java give brief answer with example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the differences between an abstract class and an interface in java?

They are very different. An abstract class is a class that represents an abstract concept (google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)


Real time example for interface vs abstract class in java?

w.frnds........ I am just trying to an example of abstract class and interface class in real life . As these two ["interface class" is not a term in Java programming - just "interface"] classes [sic] are a concept of objest orientation so easy we can easily compare thhese with our real life . Suppose we have an abstract class called clark and an abstract method behabour of this abstract class ,which has no definition in abstract class. two other class security and receptionist inherits these clark class. So in thses two derived class there must has to be a defonation of behabour method,which depends on the derived class which types of behabour they will show........ So that is a real life example of Abstract class .Interface is also same as abstract class only the difference is it can't contain any implementation of any method in base class or super class. I think this is a sufficient example to understand abstract class and interface. [No, it is not sufficient.] If u have any doubt then u can contact me with this email id-rkmahanta26@gmail.com [Interfaces support multiple inheritance; classes do not. Interfaces contain only public members; classes do not have to. Interfaces do not have superclasses, except the implicit 'Object' supertype; they have superinterfaces. Nested interfaces are always static, never inner, unlike classes which can be inner classes. "u" is not an English pronoun. Use the tutorial and the JLS to understand interfaces and abstract classes, not this garbage answer.]


What is an interface in visual basic?

An interface in visual basic is any visual thing. For example, when you're making your forms, that's an interface.


Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?

Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown). If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class. If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class. Abstract classes can even build on interfaces: public interface IMusicalInstrument { void Play(); } public abstract class MusicalInstrument:IMusicalInstrument { private int vol = 10; public virtual SetVolume(int newVol){vol = newVol;} public abstract void Play(); } public class Horn:MusicalInstrument { public override void Play(){//* Play something *//} }


How can you use abstract classes instead of interfaces?

In most cases, you will want to use abstract classes IN ADDITION to interfaces.You should use an abstract class in the following circumstance:the abstract class is clearly part of class hierarchy, and does not just describe some sort of basic functionality. Specifically, abstract classes are a good idea where they will be directly inherited from to create a concrete concept, but the abstract class itself is too indistinct to have any specific instance of it created.You want to provide an implementation for a set of methods that will be reused by a significant number of other classes, all of which can be fit into a class hierarchy.In practice, abstract classes are a good way to collect common code into one place, to make maintenance easier.For instance, say you have a class and interface structure like this:Class AInterface XClass B extends A implements XClass C extends A implements XBoth B and C will have the all the methods declared in X; if the implementation of those methods is the same (or can be made the same), then X is a good candidate for changing to an abstract method:Class AAbstract Class X extends AClass B extends XClass C extends XThus, you have removed the code duplication that was happening when using interfaces.Note that doing the above is NOT a good idea if any class which implement interface X cannot be made a subclass of the new abstract class X.

Related questions

What is the difference between data structure and abstract data type?

An Abstract Data Type is an interface that interacts with a data structure. A Data Structure is an implementation of the ADT. for example. If you were going to create a linked list you would create an Interface listing all the methods required by the list. Then in the linked list class you would code how the list uses these methods. Hope this helps :)


What are the differences between an abstract class and an interface in java?

They are very different. An abstract class is a class that represents an abstract concept (google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)


What is 3 differences between software interface and command line interface?

Differentiate between Command line interface and Menus interface and example of each interaction style


Real time example for interface vs abstract class in java?

w.frnds........ I am just trying to an example of abstract class and interface class in real life . As these two ["interface class" is not a term in Java programming - just "interface"] classes [sic] are a concept of objest orientation so easy we can easily compare thhese with our real life . Suppose we have an abstract class called clark and an abstract method behabour of this abstract class ,which has no definition in abstract class. two other class security and receptionist inherits these clark class. So in thses two derived class there must has to be a defonation of behabour method,which depends on the derived class which types of behabour they will show........ So that is a real life example of Abstract class .Interface is also same as abstract class only the difference is it can't contain any implementation of any method in base class or super class. I think this is a sufficient example to understand abstract class and interface. [No, it is not sufficient.] If u have any doubt then u can contact me with this email id-rkmahanta26@gmail.com [Interfaces support multiple inheritance; classes do not. Interfaces contain only public members; classes do not have to. Interfaces do not have superclasses, except the implicit 'Object' supertype; they have superinterfaces. Nested interfaces are always static, never inner, unlike classes which can be inner classes. "u" is not an English pronoun. Use the tutorial and the JLS to understand interfaces and abstract classes, not this garbage answer.]


What is the difference between a promina 800 and an ATM?

Promina 800's have the capability to interface to an ATM network but also can interface with many other divices for example symectric trunks up to 8Mbps IP Trunks up to 16Mbps and T-3 trunks


What is the Different Between Microprocessor and Microcontroller?

The basic difference between the microprocessor and microcontroller is that we can interface a microcontroller directly means "for example we can directly connect a keyboard to microcontroller to any of its ports"....where as for microprocessor we can't interface directly...we require a circuit board since it requires ram,ic's.....etc.,! beyrojac mahinay


What is the difference between has and have and give an example?

the difference between has and have is that you use has in sentences with : ( she , he and it ) for example : she has a book . but you use have in sentences with : ( I , you , we and they ) for example : you have a book , I have a book .


What is one example of a abstract noun?

An example of an abstract noun is knowledge.


What is the difference between a nuatral and a polictical boudary give a example of each?

A neutral boundary is a geographic feature or line that separates two areas without favoring either side politically. For example, a river or mountain range can serve as a neutral boundary between two countries. A political boundary is a demarcation line established by governments to separate territories, often based on historical, cultural, or administrative factors. An example of a political boundary is the border between the United States and Mexico, which was established through treaties and agreements between the two countries.


Difference between eg and ie?

example given......in example


Is the variable of x an example of abstract representation?

is the variable of x an example of abstract representation


What part of speech is different?

"Different" is an adjective as it describes a noun, e.g. Your meal is quite different to mine.