When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract.Aclass uses the implements keyword to implement an interface. The implements keyword appears in the class declaration following the extends portion of the declaration./* File name : MammalInt.java */public class MammalInt implements Animal{ public void eat(){ System.out.println("Mammal eats"); } public void travel(){ System.out.println("Mammal travels"); } public int noOfLegs(){ return 0; } public static void main(String args[]){ MammalInt m = new MammalInt(); m.eat(); m.travel(); }} This would produce following result:Mammal eatsMammal travels
Java
Topic: Abstract Class and Interfaces
How to implement interfaces?
Browse random answers:
How to Declare Interfaces in java?
what are the properties of interfaces?
How to implement interfaces?
How to extend intrfaces?
Explain tagging interfaces in java?
What is the difference between Abstract class and Interface?
What does it mean that a method or class is abstract?
What must a class do to implement an interface?
What is a cloneable interface and how many methods does it contain?
What is meant by "Abstract Interface"?
How to define an Interface?
Can Abstract Class have constructors? Can interfaces have constructors?
What methods would a class that implements the java.lang.CharSequence interface have to implement?
What is wrong with the following interface?public interface SomethingIsWrong { void aMethod(int aValue) { System.out.println("Hi Mom"); }}
Is the following interface valid?public interface Marker {}
Can interfaces contain inner classes?
What interface do you implement to do the sorting?
What is the eligibility for a object to get cloned?
What is the use of serializable?
Can a abstract method have the static qualifier?