Import Com.java.charpt05.NewStr;
Class Quadrangle
{
public static void Draw (Quadrangle Q)
{
System.out.println (Q.getclass (). GetName ());
}
}
public class Parallelogram extends quadrangle{
public static void Main (string[] args) {
Parallelogram q=new parallelogram ();
Draw (q);
}
}
This is an upward transformation in object type conversions. It's always safe.
2.
Import Com.java.charpt05.NewStr;
Class Quadrangle
{
public static void Draw (Quadrangle Q)
{
System.out.println (Q.getclass (). GetName ());
}
}
public class Parallelogram extends quadrangle{
public static void Main (string[] args) {
Draw (new parallelogram ());
Quadrangle Q=new Parallelogram ();
Parallelogram q=q; error
Parallelogram p= (parallelogram) q;
}
If the parent class object is given directly to the subclass object, an error occurs because the parent class object is not necessarily an instance of the subclass, and if the parent class object is cast to a child class object, this is the display type conversion.
When using the down transformation technique in a program, you must use display type conversions to indicate to the compiler which type of subclass object The parent object is converted to
Conversion of Java Object types