what is the need to cast a daughter class to a father?

1

good morning just a question since I do not have the idea of casting an object of the daughter class to a parent class (since the daughter can practically access the properties and methods of the father) I have my father class:

package interfacesypolimorfismo;

    import java.sql.Time;

    public  class cinegrafia {

    protected int sdx;

    public int TiempoDemora;
    public String nombre_pelicula;

    public cinegrafia(int TiempoDemora, String nombre_pelicula) {
    this.TiempoDemora = TiempoDemora;
    this.nombre_pelicula = nombre_pelicula;
  }

  public void cualquiercosa(){

  }




  protected void esProtected(){

 }    

 }

I also have the daughter:

   public class PeliculaDocumental extends cinegrafia{

   public String TipoDeDocumental;

    public PeliculaDocumental(String TipoDeDocumental,int 
    TiempoDemora,String 
    nombre_pelicula) {
    super(TiempoDemora, nombre_pelicula);
    this.TipoDeDocumental = TipoDeDocumental;
  }  

 }

and I do the casting:

     PeliculaDocumental xd = new PeliculaDocumental("asd", 45, "asd");

    cinegrafia xsd = (cinegrafia) xd;

but I do not find the need there since the object xd can access all the things of cinegraphy. Thank you very much for your clarification or help:).

    
asked by David Garcia 07.10.2018 в 16:52
source

0 answers