java接口对象的实例化

2019年2月16日22:56:04 发表评论 1,071 views

接口中没有构造方法,但是可以通过对象的多态性概念,通过接口的子类对其实例化。

/**
 * Created by xabcd on 2019/2/16.
 */
interface ja_jiekou
{
    public void fun1();
}
class Stu implements ja_jiekou
{
    public void fun1()
    {
        System.out.println("Student fun1()");
    }
}




/**
* Created by xabcd on 2019/2/16.
        */
public class te_jiekou
{
    public static void main(String[] args)
    {
        ja_jiekou p = new Stu();
        p.fun1();
    }
}



结果:
Student fun1()

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: