public class Point { double x,y; public
Point (double x, double y) {
public
String toString() { |
public class PointC extends Point {
|
public static void main(String arg[]){
Point p[] = new Point[6];
for(int i =0; i< p.length;i++){
if(Math.random()>0.5){
p[i]= new Point(5*i,2*i);
}
else{
p[i]= new PointC(3*i,4*i,(byte)i); //
}
System.out.println(
"\nThe points in the array are");
for(int i =0;i<p.length;i++){
System.out.print(i+": ");
if(p[i]
instanceof PointC) {
System.out.println("is PointC with color
"+((PointC)p[i]).col); //
else {
System.out.println("is Point");
}
}
}
}