פתרון בחינת בגרות שאלון 271 מדעי המחשב תשפ"ד 2024 שאלה 13 בנושא תכנות מונחה עצמים

public class AA{

private int x;

        

        public AA()

        {

                        this.x= 2;

        }

        public AA(int x)

        {

                        this.x=x;

        }

        public AA(AA a)

        {

                this.x = a.x;

        }

}

public class BB{

                private AA f;

                public BB()

                {

                        super(1);

                }

                public BB(int x, AA a)

                {

                super(x);

                this.f = new AA(a); // יוצרים משתנה חדש

                }

                public BB (AA a)

                {

                        super(x);

                        this.f = a; // יש הצבעה

                }

}