Answers for "java define interface"

20

Interface in java

// interface in java example
interface Vehicle
{
   public void accelerate();
}
class BMW implements Vehicle
{
   public void accelerate()
   {
      System.out.println("BMW accelerating...");
   }
}
public class InterfaceDemo
{
   public static void main(String[] args)
   {
      BMW obj = new BMW();
      obj.accelerate();
   }
}
Posted by: Guest on November-30-2020
6

java implement interface

// Assume we have the simple interface:
interface Appendable {
	void append(string content);
}
// We can implement it like that:
class SimplePrinter implements Appendable {
 	public void append(string content) {
   		System.out.println(content); 
    }
}
// ... and maybe like that:
class FileWriter implements Appendable {
 	public void append(string content) {
   		// Appends content into a file 
    }
}
// Both classes are Appendable.
Posted by: Guest on June-25-2020
0

java define interface

/* File name : Animal.java */
interface Animal {
   public void eat();
   public void travel();
}
Posted by: Guest on April-23-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language