interface function java code example
Example 1: Interface in java
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();
}
}
Example 2: java interface
public interface Exampleinterface {
public void menthod1();
public int method2();
}
class ExampleInterfaceImpl implements ExampleInterface {
public void method1()
{
}
public int method2()
{
}
}
Example 3: how to declare a interface in java
interface Appendable {
void append(string content);
}
class SimplePrinter implements Appendable {
public void append(string content) {
System.out.println(content);
}
}
class FileWriter implements Appendable {
public void append(string content) {
}
}
0
how to implement a interface in java
Example 4: java define interface
interface Animal {
public void eat();
public void travel();
}