UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What are the difference between abstract class and Interface?

Asked by Last Modified  

19 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Abstraction : Hiding unnecessary details of object and shows only essential features of Object to communicate. abstract class : partially defined Object interface :Complete specification of Object class : Complete definition of Object
Comments

Expert Software Developer working in CMMI Level 5 company as JAVA/J2EE developer.

Interface is alternative for multiple inheritance.
Comments

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior. Variables declared in a Java interface is by default final. An abstract class may contain non-final variables. Members...
read more
Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior. Variables declared in a Java interface is by default final. An abstract class may contain non-final variables. Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc.. Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”. An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces. A Java class can implement multiple interfaces but it can extend only one abstract class. Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists. In comparison with java abstract classes, java interfaces are slow as it requires extra indirection. read less
Comments

MSC (CS), PGDBA, DOEACC A/O level, ADCST Java Certified, Manual Testing certified, Rational IBM certifies

A class must be declared abstract when it has one or more abstract methods. A method is declared abstract when it has a method heading, but no body -- which means that an abstract method has no implementation code inside curly braces like normal methods do. An interface differs from an abstract class...
read more
A class must be declared abstract when it has one or more abstract methods. A method is declared abstract when it has a method heading, but no body – which means that an abstract method has no implementation code inside curly braces like normal methods do. An interface differs from an abstract class because an interface is not a class. An interface is essentially a type that can be satisfied by any class that implements the interface. example public abstract class Figure { /* because this is an abstract method the body will be blank */ public abstract float getArea(); } public class Circle extends Figure { private float radius; public float getArea() { return (3.14 * (radius * 2)); } } public interface Dog { public boolean Barks(); public boolean isGoldenRetriever(); } Now, if a class were to implement this interface, this is what it would look like: public class SomeClass implements Dog { public boolean Barks{ // method definition here } public boolean isGoldenRetriever{ // method definition here } } read less
Comments

Tutor - Maths and computer science

An interface differs from an abstract class because an interface is not a class. An interface is essentially a type that can be satisfied by any class that implements the interface. Any class that implements an interface must satisfy 2 conditions: It must have the phrase "implements Interface_Name"...
read more
An interface differs from an abstract class because an interface is not a class. An interface is essentially a type that can be satisfied by any class that implements the interface. Any class that implements an interface must satisfy 2 conditions: It must have the phrase "implements Interface_Name" at the beginning of the class definiton. It must implement all of the method headings listed in the interface definition. 1. Abstract classes are meant to be inherited from, and when one class inherits from another it means that there is a strong relationship between the 2 classes. For instance, if we have an abstract base class called "Canine", any deriving class should be an animal that belongs to the Canine family (like a Dog or a Wolf). The reason we use the word "should" is because it is up to the Java developer to ensure that relationship is maintained. With an interface on the other hand, the relationship between the interface itself and the class implementing the interface is not necessarily strong. For example, if we have a class called "House", that class could also implement an interface called "AirConditioning". Having air conditioning not really an essential part of a House (although some may argue that point), and the relationship is not as strong as, say, the relationship between a “TownHouse” class and the "House" class or the relationship between an “Apartment” class that derives from a “House” class. Because a TownHouse is a type of House, that relationship is very strong, and would be more appropriately defined through inheritance instead of interfaces. So, we can summarize this first point by saying that an abstract class would be more appropriate when there is a strong relationship between the abstract class and the classes that will derive from it. Again, this is because an abstract class is very closely linked to inheritance, which implies a strong relationship. But, with interfaces there need not be a strong relationship between the interface and the classes that implement the interface. read less
Comments

Technology Trainer(C, C++, Java , DS , DBMS etc)

Abstract class can have both abstract methods as well as non abstract , whereas interface can have only abstract methods.
Comments

Java/J2EE/SFDC Corporate Trainer

Abstract class is the class which is partially implemented means it contains some defined methods and undefined methods but in case of interface only we have undefined methods and final initilized variables means interface is a specification implemented in a class. In general we use interfaces for module...
read more
Abstract class is the class which is partially implemented means it contains some defined methods and undefined methods but in case of interface only we have undefined methods and final initilized variables means interface is a specification implemented in a class. In general we use interfaces for module collaboration in project scenario. read less
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Interfaces are rules (Rules because you must give an implementation to them and that you can't ignore or avoid, so that are imposed like rules) which works as a common understanding document among the various teams in software development. Interfaces give the idea what is to be done but not how it...
read more
Interfaces are rules (Rules because you must give an implementation to them and that you can't ignore or avoid, so that are imposed like rules) which works as a common understanding document among the various teams in software development. Interfaces give the idea what is to be done but not how it will be done. So implementation completely depends on developer by following the given rules(Means given signature of methods). Abstract classes may contain only abstract declarations or only concrete implementations or mixed. Abstract declarations are like rules to be followed and concrete implementations are like guidelines(You can use that as it is or you can ignore it by overriding and giving your own choice implementation to it). Moreover which methods with same signature may change the behaviour in different context are provided as interface declarations as rules to implement accordingly in different contexts read less
Comments

I am best in java and J2ee because i worked in small company.

Abstract class not supported the multiple inheritance in java and this problem solve by interface using implements keywords.
Comments

I am best in java and J2ee because i worked in small company.

In interface all variable are public final static ,all method are public abstract and all inner class are static automatically by jvm but in abstract class this type of property not exists.
Comments

View 17 more Answers

Related Questions

Why is finally introduced in Java?
finally is block which executes every time regardless exception has occurred or not. Finally is important in case you want to do some task which must be done like clean-up, db connection closure, memory de-allocation etc.
Agastya
Is synchronized keyword necessary, in Java, if everything that is modified in a function is local to that function?
No, it is not required if you make sure whatever parameters are updated/modified will be done as atomic references/operations. Atomicity is an alternative to syncronizatiom.
Abishiek
0 0
6
Is Java a language or a technology?
java is both language and technology. Java platform serves as technology.
Sammeyka
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Overloading in JAVA
When a class contains more than one method with the same method name but different argument types, then it is called Overloading. Methods are said to be Overloaded methods. Also, know as Compile time...

What Is Java? Explain The History Of Java
i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java...

2.1. Reverse a singly linked list.
class Node { int data; Node next; Node(int data) { this.data = data; this.next = null; }} public class LinkedList { Node head; public void reverse() { Node prev = null; Node curr = head; Node next =...

Differences Between HashMap vs HashSet In Java.
HashSet HashMap HashSet implements Set interface. HashMap implements Map interface. HashSet stores the data as objects. HashMap stores the data as key-value pairs. HashSet...

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Recommended Articles

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more