继承

package wang;

/**

  • @author wangyongsheng
  • @date 2021/4/23 8:11
    */
    public class uncle {
    private String name;
    private int age;

public uncle(){
System.out.println("舅的构造方法被创建");
}
public void fahongbao(){
System.out.println("发红包");
}
public void maiche(){
System.out.println("舅舅送车");
}
}
package wang;

/**

  • @author wangyongsheng
  • @date 2021/4/23 8:12
    */
    public class UncleOne {
    public void hejiu(){
    System.out.println("大舅喜欢喝酒");
    }
    public void faHongbao(){
    System.out.println("大舅喜欢发红包");
    }
    }
    package wang;

/**

  • @author wangyongsheng
  • @date 2021/4/23 8:13
    /
    public class demo05 {
    public static void main(String[] args) {
    /
    UncleOne uncleOne=new UncleOne();
    uncleOne.faHongbao();
    uncleOne.hejiu();
    UncleTwo uncleTwo=new UncleTwo();
    uncleTwo.fahongbao();
    uncleTwo.chouyan();*/
    UncleTwoSon uncleTwoSon=new UncleTwoSon();
    /*uncleTwoSon.fahonhgbao();
    uncleTwoSon.maiche();*/
}

}
package wang;

/**

  • @author wangyongsheng
  • @date 2021/4/23 9:10
    */
    public class demo06 {
    public static void main(String[] args) {
    final int a=1;
    final int []b={1,2,3};
    b[0]=10;
    b[1]=20;
    b[2]=30;
    int []c=new int[3];
    //b=c;
    }
    }
    package wang;

/**

  • @author wangyongsheng

  • @date 2021/4/23 8:13
    */
    public class UncleTwo extends uncle {

    public UncleTwo(){
    System.out.println("二舅的构造方法");

    }

//独有的方法
public  void  chouyan(){
    System.out.println("二舅喜欢抽烟");

}
//复写(腹写)Override 父类中的方法
public void fahongbao(){
    System.out.println("家道中落,不发红包");
}

}

package wang;

/**

  • @author wangyongsheng
  • @date 2021/4/23 8:31
    */
    public class UncleTwoSon extends UncleTwo{
    public UncleTwoSon(){
    super(); //调用二舅方法
    System.out.println("二舅儿子的方法被创建");
    }
    public void fahonhgbao(){
    System.out.println("逆袭了,红包接着发");
    }

}

你可能感兴趣的:(继承)