package com.template;
import org.junit.Test;
public class Trest {
Shoes shoes=null;
Clothes clothes=null;
@Test
public void test() {
shoes=new Shoes();
clothes=new Clothes();
shoes.shopping();
clothes.shopping();
}
}
package com.template;
public class Clothes extends Shopping{
@Override
public void buy() {
// TODO Auto-generated method stub
System.out.println("买了一件衣服");
}
@Override
public void pay() {
System.out.println("微信支付");
}
}
package com.template;
public class Shoes extends Shopping{
@Override
public void buy() {
// TODO Auto-generated method stub
System.out.println("购买了一双鞋子");
}
@Override
public void pay() {
System.out.println("支护宝付款");
}
}
package com.template;
public abstract class Shopping {
public void shopping() {
userlogin();
buy();
pay();
}
//final方法不让子类继承
public final void userlogin() {
System.out.println("用户登录");
}
//抽象方法子类必须实现
public abstract void buy() ;
//付款方式默认一种,子类可以重写
public void pay() {
System.out.println("使用银联支付");
}
}