java 子类与父类转换
比如在这个类中:publicvoidpaint(Graphicsoldg){Graphics2Dg=(Graphics2D)oldg;BasicStrokestroke=...
比如在这个类中:
public void paint(Graphics oldg)
{
Graphics2D g = (Graphics2D)oldg;
BasicStroke stroke = new BasicStroke(10);
g.setStroke(stroke);
Line2D line = new Line2D.Float(0,0,20,30);
g.draw(line);}
父类Graphics转换成了子类Graphics2D,并且使用子类的方法,不是说父类不能转换成子类的吗? 展开
public void paint(Graphics oldg)
{
Graphics2D g = (Graphics2D)oldg;
BasicStroke stroke = new BasicStroke(10);
g.setStroke(stroke);
Line2D line = new Line2D.Float(0,0,20,30);
g.draw(line);}
父类Graphics转换成了子类Graphics2D,并且使用子类的方法,不是说父类不能转换成子类的吗? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询