美文网首页
abstract class与interface

abstract class与interface

作者: 秦汉邮侠 | 来源:发表于2015-10-30 22:50 被阅读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

再说结论

相关文章

网友评论

      本文标题:abstract class与interface

      本文链接:https://www.haomeiwen.com/subject/ijifhttx.html