נתון עץ הירושה הבא: Shape -> Square, Triangle, Circle; Square -> Rectangle; Circle -> Ellipse. לפניכם קטע קוד מתוך הפעולה הראשית: Shape s1 = new Shape(); Shape s2 = new Square(); Shape s3 = new Rectangle(); Square sq = new Rectangle();
נתון עץ הירושה הבא: Shape -> Square, Triangle, Circle; Square -> Rectangle; Circle -> Ellipse. לפניכם קטע קוד מתוך הפעולה הראשית: Shape s1 = new Shape(); Shape s2 = new Square(); Shape s3 = new Rectangle(); Square sq = new Rectangle();
hierarchyDiagram: root: Shape
children: [Square, Triangle, Circle]
grandchildren: Square: [Rectangle]
Circle: [Ellipse]
לפניכם שמונה קטעי קוד. עבור כל אחד מהסעיפים יש לציין אם הקוד תקין או לא. אם הקוד אינו תקין – יש להסביר למה הקוד אינו תקין ולציין את סוג השגיאה (שגיאת קומפילציה/הידור, או שגיאת זמן ריצה).
codeTable:
-
- Square sq1 = new Shape();
-
- Square sq2 = s1;
-
- Square sq3 = (Square)s2;
-
- Square sq4 = (Square)s3;
-
- Square sq5 = (Square) s1;
-
- Triangle t = new Triangle(); Shape s6 = t; Square sq6 = (Square)s6;
- 7. Shape s7 = (Square)(new Rectangle());
- 8. Square sq8 = (Shape)(new Rectangle());
> **structuralNote:** The 8-item cast/compile-error list is byte-identical in content between languages, but the PRINTED NUMBERING is CONTINUOUS across the two language sections (Java: items 1-8, C#: items 9-16 for the exact same content) rather than restarting at 1 in each section. This differs from the pilot paper (97105_2026_spring_a), where the analogous table restarted 1-6 identically in both language sections. Do not assume item numbering resets per language section across this exam's corpus — verify per paper.
רוצים לכתוב פעולה אשר מקבלת מערך של צורות (מערך הפניות לעצמים מטיפוס Shape) ומחזירה את סכום השטחים של כל המשולשים (Triangle) והמלבנים (Rectangle). באיזו מחלקה או מחלקות יש להוסיף את הפעולה [double area()/double Area()] המחשבת ומחזירה שטח? הסבירו את תשובתכם.
methodRef: double area()
public static Triangle maxArea(Shape[] arr)
כתבו פעולה המקבלת מערך צורות ומחזירה את המשולש ששטחו הגדול ביותר. אם במערך אין אף משולש, הפעולה תחזיר null.
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.