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

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

Abstract and Interface both are used for inheritence. :) Abtract classes are used in IS-A relationship. Interfaces can be used in both IS-A and HAS-A relationship. Abstract classes are used for Specialization Example: class RentedHouse extends House{} // House is abstract, class Apple extends...
read more
Abstract and Interface both are used for inheritence. :) Abtract classes are used in IS-A relationship. Interfaces can be used in both IS-A and HAS-A relationship. Abstract classes are used for Specialization Example: class RentedHouse extends House{} // House is abstract, class Apple extends Fruit{} // Fruit is abstract class Dog extends Animal{} // Animal is abstract Interfaces are used for Generalization. Example: interface Switch{} // with on and off method class DVDPlayer implements Switch{} // class has to give the implementation of switch. class RentedHouse implements Switch{} // Hope I made it clear. 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

Software Trainer

Basic Difference Abstract Class:- 1. Abstract class can contain abstract as well as non abstract methods. 2. In abstract class constructor also possible. 3. In Abstract class methods must be declared as public. Interface:- basically used for multiple inheritance. 1. Interface can contains...
read more
Basic Difference Abstract Class:- 1. Abstract class can contain abstract as well as non abstract methods. 2. In abstract class constructor also possible. 3. In Abstract class methods must be declared as public. Interface:- basically used for multiple inheritance. 1. Interface can contains only abstract methods. 2. In interface constructor not possible. 3. No need to mention access specifiers(public, private...) because all method by default public. read less
Comments

I have 8+ yrs of industry working experience in PHP, MySQL, Javascript, JQuery, Ajax

Here a couple of things to know about each one. 1. Methods in abstract classes can be defined abstract or just a regular method. If a method is abstract, then that method must be defined in the class that extends it. In interfaces, ALL methods are abstract, therefore all methods must be defined in the...
read more
Here a couple of things to know about each one. 1. Methods in abstract classes can be defined abstract or just a regular method. If a method is abstract, then that method must be defined in the class that extends it. In interfaces, ALL methods are abstract, therefore all methods must be defined in the class that implements them. 2. You’re allowed to define your methods as public, private, or protected in abstract classes. In interfaces, ALL methods MUST be public. 3. In abstract classes, you’re allowed to create methods and properties with values and concrete code in them as long as they’re not defined as abstract. Interfaces CAN NOT contain properties and methods CAN NOT have a body. 4. A class can only extend 1 abstract class, but a class can implement an infinite amount of interfaces even if the interfaces don’t relate to one another. class Cookie implements Recipe, Business 5. You have an option to override methods in an abstract class, but you MUST override ALL methods in an interface. Interfaces are a bit more stricter than abstract classes. Interfaces are meant to be used just as a template or empty shell for other classes to follow a certain logic. Abstract classes are lenient and can contain some helpful methods and properties for any class that extends it. 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

What are different IDEs available to write programs?
There are many IDE for programming like TurboC++,Dev C++ for C and C++ programming. Eclipse,Notepad++,Dreamweaver for HTML,PHP,JAVA,ASP etc languages.
Meraj
0 0
5
Can I build iPhone apps using Python?
Yes, you can use PyMob app where apps can be written purely in Python, and the compiler tool flow converts them in native source codes for various platforms. But there are some cons on using PyMob, the...
Sunil
0 0
5
When to use transient variables?
To know about transient , first we need to know about serialization concept .serialization makes an object's state persistent . It means that the object is converted into stream and store in a file . For...
Jay Shah
Why is finally introduced in Java?
Finally is introduced in Java to do the code clean up or if you wants to perform some operation irrespective of whether the code throws an Exception or not.
Agastya
What is the purpose of using throws keyword in java?
The throws statement is how you create an exception stack trace. There isn't much magic in java--it's not some underlying system mystery that creates an exception, it is simply a "Throw" statement, and...
Saritha

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

Ask a Question

Related Lessons

Free selenium video tutorial
Hi All, Hope you are doing good. We uploaded few videos on Selenium components like IDE, RC and Webdriver on youtube channel you can watch them for free of cost. Kindly search with below link: ...
S

Method Overloading vs Method Overriding
1. Method Overloading: Method overloading means a same method with same name can have different implementations/body by changing one of the follwing thing: 1) Number of Parameters 2) Order of Parameters 3)...

Features Of Java
There is given many features of Java. They are also known as java buzzwords. The Java Features given below are simple and easy to understand. Simple. Object-Oriented. Portable. Platform independent. Secured. Robust. Architecture...
V

Class, Object and Methods in JAVA
Lesson-1: Class, Object and Methods of Java can be compared with body, heart and brain. Without these 3 things, Java does not exist. If you Google the above 3 items, you will find many definitions. But...

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

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