编程语言
首页 > 编程语言> > 【JAVA】代码执行顺序题目

【JAVA】代码执行顺序题目

作者:互联网

代码执行顺序的题目

public class TestClass {
    static  class Father{
        public int money = 1;

        public Father() {
            this.money = 2;
            showMoney();
        }

        protected  void showMoney(){
            System.out.println("I am Father , I hava $"+money);
        }
    }

    static  class Son extends Father{
        public int money = 3;

        public Son() {
            this.money = 4;
            showMoney();
        }

        protected  void showMoney(){
            System.out.println("I am Son , I hava $"+money);
        }
    }
    public static void main(String[] args) {
        Father guy = new Son();
        System.out.println("This guy has $"+guy.money);
    }
}

结果:

在这里插入图片描述

流程:

标签:showMoney,题目,money,Father,Son,代码执行,JAVA,guy,public
来源: https://blog.csdn.net/zxfhahaha/article/details/112664299