Search:

Type: Posts; User: KevinWorkman

Search: Search took 0.18 seconds.

  1. Replies
    8
    Views
    4,724

    Re: Is Downcasting possible in Java??

    To use your example:

    Animal a = new Animal();
    Animal c = new Cat();
    Cat cat = (cat)c;
    c.meow(); //can't do this, there is no guarantee that c has a meow method
    cat.meow(); //can do this, the...
  2. Replies
    8
    Views
    4,724

    Re: Is Downcasting possible in Java??

    It depends on your definition of "downcasting".

    You cannot convert an Animal into a Cat. But if an instance of Cat is stored as an Animal (or Object, whatever), then you can indeed cast that as a...
Results 1 to 2 of 2