面试题:Java多态重载中类型转换与方法选择
考虑以下Java代码片段:
```java
class Shape {
public void draw() {
System.out.println("Drawing a shape");
}
}
class Circle extends Shape {
@Override
public void draw() {
System.out.println("Drawing a circle");
}
public void draw(int radius) {
System.out.println("Drawing a circle with radius " + radius);
}
}
class Rectangle extends Shape {
@Override
public void draw() {
System.out.println("Drawing a rectangle");
}
public void draw(int width, int height) {
System.out.println("Drawing a rectangle with width " + width + " and height " + height);
}
}
public class Main {
public static void main(String[] args) {
Shape shape1 = new Circle();
Shape shape2 = new Rectangle();
// 如果要调用Circle类中带参数的draw方法和Rectangle类中带参数的draw方法,应该如何进行类型转换并调用?请写出代码,并解释为什么要这样做。