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