يا جماعة هذه أول مشاركة الي .. الحقيقة كنت ببحث عن حل لسؤال ما عرفت احله .. او بالاحرى مش فاهمة شو بدو
فيا ريت تساعدوني بسرعة و مشكورين
Apply the following then mention and discuss the output
class Shape {
void draw() {}
void erase() {}
}
class Circle extends Shape {
void draw() {
System.out.println("Circle.draw()");
}
void erase() {
System.out.println("Circle.erase()");
} }
class Square extends Shape {
void draw() {
System.out.println("Square.draw()");
}
void erase() {
System.out.println("Square.erase()");
}}
class Triangle extends Shape {
void draw() {
System.out.println("Triangle.draw()");
}
void erase() {
System.out.println("Triangle.erase()");
}}
1. Build the main class Shapes that contains a static method randShapeegg that produces a reference to a randomly-selected Shape object each time you call it.
The mainegg should contains an array of ten Shape references filled through randShapeegg. through this array call drawegg for each one
2. Add a new type of Shape and verify in mainegg that polymorphism works for your new type as it does in the old types.
3. Add a new method in the base class that prints a message, but don’t override it in the derived classes, call it in the main as you did with draw(),.Explain what happens. Now override it in one of the derived classes but not the others, and see what happens. Finally, override it in all the derived classes.
4. Add a new method in the Square class that prints its name, call it in the main as you did with draw(),explain what happens, explain how we can use it correctly?