Java从入门到精通 - 继承多态

class CopyOfQuadrangle
{
 private CopyOfQuadrangle[] qtest = new CopyOfQuadrangle[6]; //实例化保存四边 形的数组对象
 private int nextindex = 0;
 public void draw(CopyOfQuadrangle q )
 {
  if(nextindex <qtest.length)
  {
   qtest[nextindex] = q;
   System.out.println(nextindex);
   nextindex ++;
  }
 }
}
 
public class 多态 {
     public static void main(String args[])
     {
      CopyOfQuadrangle q = new CopyOfQuadrangle();
      q.draw(new CopyOfSquare());
      q.draw(new CopyOfParallelogramgle());
     }
}

class CopyOfSquare extends CopyOfQuadrangle
{
 public CopyOfSquare()
 {
  System.out.println("正方形");
 }
}
class CopyOfParallelogramgle extends CopyOfQuadrangle
{
 public CopyOfParallelogramgle()
 {
  
  System.out.println("平行四边形");
 }
}

你可能感兴趣的:(Java从入门到精通 - 继承多态)