Interfaces
//interface example
interface Inter
{
void connect();
}
//implementation classes
class Oracle implements Inter
{
public void connect()
{
System.out.println("Connecting to Oracle database..........");
}
}
class Sybase implements Inter
{
public void connect()
{
System.out.println("Connecting to sybase database..............");
}
}
class Interface
{
public static void main(String[] args) throws Exception
{
//Accepting database name from commandline args & store it in an obj c
Class c = Class.forName(args[0]);
{
//create an obj to that class whose name is in c
MyInter mi=(MyInter)c.newInstance();
{
//call conect method of obj
mi.connect();
}
}
}
}
Sunday, August 19, 2007
Interfaces in Java
Posted by ramesh at 8:53 AM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment