Google

Sunday, August 19, 2007

Interfaces in Java

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();

}

}

}

}

No comments: