abstract class与interface

2015-10-30  本文已影响30人  秦汉邮侠

1.先上代码

hello

abstract class MobilePhone {

    abstract public void showcompany();
    public void showoperationsystem() { 
        System.out.println("Anroid");   
    }   
}

class HuaweiMobilePhone extends MobilePhone {
    public void showcompany()
    {
        System.out.println("Huawei");
    }
}

class SamsungMobilePhone extends MobilePhone {
    public void showcompany()
    {
        System.out.println("Samsung");
    }
}

class ApplePhone extends MobilePhone {
    public void showcompany()
    {
        System.out.println("Apple");
    }
    public void showoperationsystem() { 
        System.out.println("IOS");  
    }   
}

public class AbstractClassTest {
    public static void main(String[] args) {
        MobilePhone phone;
        phone = new HuaweiMobilePhone();
        phone.showcompany();
        phone.showoperationsystem();
        phone = new SamsungMobilePhone();
        phone.showcompany();
        phone.showoperationsystem();
        phone = new ApplePhone();
        phone.showcompany();
        phone.showoperationsystem();        
    }
}

hello

再说结论

上一篇下一篇

猜你喜欢

热点阅读