lundi 7 mars 2016

how to call implementation class methods in run method without hardcoding

interface Myinterface
{
boolean run();
}

class MyClass implements Myintr
{
      boolean run()
      {
          boolean status=false;
           disp();//hard coded
           show();//hard coded

here above two methods are hard coded how can we call without hard coding } public void disp() { System.out.println("Hello Person"); }

      public void show()
      {
               System.out.println("Welcome");
       }

}

class Mainclass
{
public static void main(String args[])
{

   Class aClass=Class.forName("Myclass");
   Object obj=aClass.newInstance();
   Myinterface myinter=(Myinterface)obj.run();

} }





Aucun commentaire:

Enregistrer un commentaire