Skip to content

Instantly share code, notes, and snippets.

@kenorb
Last active August 29, 2015 14:04
Show Gist options
  • Save kenorb/ee39910b48bcb827537e to your computer and use it in GitHub Desktop.
Save kenorb/ee39910b48bcb827537e to your computer and use it in GitHub Desktop.
Interface Class Demo.
/*
* Interface Class Demo.
*
* - An interface is a specification of method signatures.
* - Interface is syntatically similar to class declaration,
* but it lacks of instance variables (no instance variables).
* - An interface can extend one or more interfaces at one time.
* - Interfaces cannot be instantiated,
* because they represent pure abstract concept.
* - Interface can only include abstract methods.
* - A class cannot extend an interface, it simply implements it.
*
* Methods of interface are public and abstract by default.
*
* class to class - extends
* class to interface - implements
* interface to interface - extends
* class cannot extend interface
*
* Usage:
* javac InterfaceClass.java
* java InterfaceDemo
*/
interface Database {
void getConnection();
}
class Impl implements Database {
public void getConnection() {
System.out.println("Connecting to the database.");
}
}
class InterfaceDemo {
public static void main(String[] args) {
Impl i1 = new Impl();
i1.getConnection();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment