面向对象编程(OOP)

//鸟类
public class Bird {
    
    //属性 成员变量
    
    //颜色
    String Color;
    
    //重量
    double weigt;
    
    
    //行为  方法
    
    //飞 void - 没有返回值
    void fly()
    {
        System.out.println("我能飞");
    }
    //
    void eat()
    {
        System.out.println("我喜欢吃虫子");
    }
    
    public static void main(String[] atgs)
    {
        //生成一直鸟的实例 老鹰
        Bird eagle = new Bird();
        
        eagle.Color = "灰色";
        eagle.weigt = 10;
        
        System.out.println("这是一只鸟 颜色是" + eagle.Color);
        
        eagle.fly();
        
        eagle.eat();
        
        
        
    }

}

原文地址:https://www.cnblogs.com/future-zhenzhen/p/5240318.html