A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Over_Mstuang 中级黑马   /  2015-8-7 23:48  /  173 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
        接口的成员特点:
                成员变量:接口中只有常量。
                                  因为接口的成员变量有默认修饰符:
                                        public static final
                                        推荐:永远自己给出修饰符。
                构造方法:
                                  没有构造方法。
                                  任何类如果没有继承父类,那么这个类就继承自Object类。
                成员方法:接口中的方法都是抽象的。
                                  因为接口中的成员方法有默认修饰符:
                                        public abstract
                                        推荐:永远自己给出修饰符。
                               
*/
interface Animal
{
        int num = 100;
        public int x = 10;
        public final int y = 20;

        //public Animal(){}

        //public void method();
        //abstract void method();
        public abstract void method();
}

class Dog implements Animal
{

        public Dog()
        {
                super();
        }

        public void show()
        {
                //x = 30;
                System.out.println(x);
                System.out.println(y);
                System.out.println(Animal.x);
                System.out.println(Animal.y);
        }
       
        public void method()
        {
                System.out.println("dog method");
        }
}

class InterfaceDemo2
{
        public static void main(String[] args)
        {
                Dog d = new Dog();
                d.show();
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马