Interface as a parameter and return value of a method
Interface smoking:
public interface Smoking { public static final int a=1; public abstract void smoking();
}
Student class implements the interface:
Public class student implements smoking {public void smoking() {system. Out. Println ("please don't smoke");}
}
Test the testarguments class:
Public class testarguments {public static void main (string [] args) {/ / call the nosmoking method and pass the implementation class object. / / when implementing the class object, you will create your own object, student s = new student(); nosmoking (s); nosmoking (New student()); / / the implementation class object, which is created by polymorphism. Smoking t = new student(); nosmoking (T);} / ** Define a method, and write the method parameters as interface type * / public static void nosmoking (smoking s) {/ / the reference variable s of the interface calls method s.smoking(); / / call the constant a system.out.println (smoking. A) in the interface;}}