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

Can you use abstract and final both with a method? Why?
No because we have to provide an abstract method with implementation in the subclass (the child class of the parent class in which the abstract method was declared). And for providing this implementation...
Sushil
What are the core concepts of Java?
OOPs, Flow control, String Handling, generics, exception, threading, collection, IO, JDBC are some core concepts of Java.
Manish
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

Difference Of Inheritance In C++ And Java
In Java , multiple inheritance is not applicable directly but we can implement the concept by using the interfaces. In c++ and Java, the common types of inheritances are: Single Multi level Hybrid Hierarchical

Example of DependsOnMethod in TestNG
public class dependsonM { @Test public void login() { System.out.println("login"); } @Test (dependsOnMethods = {"login"}) public void email() { //Intentionally I am failing this testcase Assert.assertTrue(false);...
S

Sarthak C.

0 0
0

Lambda Expressions in Java
A lambda expression, introduced in Java 8 is similar to a block of code resembling an anonymous function that can be passed to constructors or methods for execution as an argument. Examples: a)() ->...

Java and C trainer
Always think any conspect with real-time example like Object -- object must have states and behaviour then only we will call that thing is Object like fan is Object (rotating,color)

Palindrome Number : Java Function
An easier way to find out whether a number is a Palindrome number or not. Eg. 121, 88, 12321 etc public boolean isPalindrome ( int n ) { int rev = 0, r; for( i = n; i > 0; i /= 10 ) { r...

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