Interface with class and interface as member

/**
 *
 * @author bhavesh
 */


public interface MyOuterInterface {
   
// static class

    public  class myinn {
       
        private int var;
       
        public void setVar(int v) {
           
            var =v;
        }
        public int getVar()  {  return var; }
    }
   
    // static interface

    public interface myint {
       
    }
   
}


// Use of above interface with its inner class  example

/**
 *
 * @author bhavesh
 */
public class MainOuterClass {

       public static void main(String[] args) {
        
        MyOuterExample me = new MyOuterExample();
        
        me.callMethod();
       
      
    }
    
}

class MyOuterExample implements MyOuterInterface {
    
   myinn my = new myinn();
   
  public void callMethod() {
      
      my.setVar(20);
      System.out.println("value of interface  : .. " +my.getVar() );
  }
}



Comments

Popular posts from this blog

Custom Exception example for BankAccount

Annotation