+ 1
what is the diffetence when we say an interface extends another interface and a class implements an interface?
11 Réponses
+ 1
Abdul Wahab If you use the keyword abstract for the child class declaration then you cannot call it a concrete(non-abstract) class.
Also remember that an abstract class need not have an abstract method, it can also have only non-abstract methods but if you declare a method abstract inside the class then your class should be declared abstract.
+ 5
A class can also extend another class.
+ 4
extending an interface means you are inheriting from an interface to extend its functionalities...
a class implementing an interface means a class has to do whatever that interfaces dictates. unless the class is declared as abstract.
+ 4
An interface provides just the methods.
It can extends an interface.
For example you have an interface animal and an interface bird:
interface Bird extends Animal
This makes sense because all Birds are Animals.
But without implementing the interface Bird both interfaces would make no sense. Because an interface can't create objects.
It just used for the behavior of a class.
public class Hawk implents Bird
Here you implement all methods of Animal and all methods of Bird.
In short: Interfaces describes what classes should do, without specifying how they should do it.
+ 3
Always remember that interface contains abstract methods(not including default and static for simplification). So when we say an interface extends another interface then the extending interface need not give implementation for the inherited methods.
Whereas when we say a class implements an interface and if it is a concrete class(non-abstract) then it should give implementation for all the methods it has inherited from the interface.
+ 2
Avinesh thnks for your time. It helpd me allot
+ 2
It's good to know Abdul Wahab and you're welcome.
+ 1
if a class provides all the function bodies of an interface, then it would be concrete and then it would not be considered as abstract. Is it correct?
bahha Denise Roßberg Avinesh
+ 1
Abdul Wahab yes
0
and is it true to say that an abstract child class that implements an interface becomes concrete only if it provides all the function bodies of its parent abstract class and function bodies of interface that it implements?