This is a completely different level of abstraction. A library has an interface (an API).
You cannot explain Java Interfaces and Java abstract classes this way.
please go elsewhere to find solutions to your homework assignment.
The library would be a good place, or better yet your course notes and required books.
Without knowing how much you know about Interfaces and Abstract Classes, my first recommendations are to take a look at:
- http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html and any other topics of interest on the left-hand side bar on that page
- Java - Interfaces
- Java - Abstraction
- Java Abstract Classes
Hi I have Studied The Above urls ,I got that main difference between Abstract Class and interface is the
1)The interface is mainly used to achieve the multiple inheritance.And abstract class is used when we have a partial implementation of the methods in your class we should make our class as an abstract.
2)And for both interface and abstract class should not be instantiated.We can create the subclass for thous.
3)In the interface subclass we must override the methods in the interface in our subclass.
4)In the Abstract class we must override only the abstract methods.Other methods depends.
5)Interfaces are mainly used to hold static content bcz inside interface the varibles are by diffalt static,final.
this are the main differences i would have find from that tutorial ,Can u please give me one real time scenario for the abstract and interface.And can please explain me other differences except those..
Your list mixes differences and usage guidance.
Real life example of how to use both is interface TableModel and abstract class DefaultTableModel from javax.swing package.
If you're trying to choose between an interface and an abstract class, my rules of thumb are:
1. If you need to implement/inherit multiple things, use interfaces. You can implement multiple interfaces, but can extend only a single class.
2. If you want to provide default behaviors (i.e., methods) that multiple extending/implementing classes can use, go with an abstract class. This guideline may change somewhat with default interface behaviors in Java 8, though.
If you need both # 1 & # 2 above, you probably should take a hard look at your overall design to see if it needs re-thinking.
If there is a easier relation ship between the class then we can go for abstract class.
Let take the example..
abstract class Mammals (It may be a HumanBeing or Animal)
Can set with two eyes;
abstract legs(); // we can’t define the method. So it should be a abstract. Because human
has two legs where as animals have four legs.
Completely different class has a same behaviours.
Bird Airplane Superman
Here three class have a same behaviour (flyer) but different implementation .