抽象类的实例化

package t0513;
/**
 * 
 */

/**
 * @author LU
 *
 * 2021年5月13日
 */
//抽象类
public abstract class Animal {
    
        //抽象方法
        public abstract void fly();
        //非抽象方法
        public void run(){
            System.out.println("四条腿跑得飞快!!");
        }
        //无参构造
        Animal(){}
        
        //静态方法,返回此类的一个对象
        public static Animal newone(){
            
                return new Animal(){
                @Override
                public void fly() {
                    System.out.println("俩翅膀飞得贼高!");
                }
            };
            //return this;
        }
    }

    
     
 1 package t0513;
 2 
 3 /**
 4  * 
 5  */
 6 
 7 
 8 /**
 9  * @author LU
10  *
11  * 2021年5月13日
12  */
13 public class Test2 {
14         public static void main(String[] args) {
15             //直接new一个抽象类的( 子类?)对象 地址
16            Animal dog =new Animal() {
17                 @Override
18                 public void fly() {
19                     System.out.println("四条腿飞不起来!");                
20                 }
21            };
22         
23             dog.run();
24             dog.fly();
25             
26             //通过静态方法得到一个(子类?)对象地址
27             Animal bird=Animal.newone();
28             bird.run();
29             bird.fly();
30         
31         }
32     
33     
34 }
原文地址:https://www.cnblogs.com/chang09/p/14765324.html