Skip to content

Instantly share code, notes, and snippets.

@ozgun
Created June 3, 2013 13:30
Show Gist options
  • Select an option

  • Save ozgun/5698142 to your computer and use it in GitHub Desktop.

Select an option

Save ozgun/5698142 to your computer and use it in GitHub Desktop.
public class DowncastingExample {
public static void main(String args[]) {
Object[] o = new Object[2];
o[0] = new Hayvan(); // upcasting
o[1] = new Kedi(); // upcasting
Hayvan a2 = (Hayvan) o[0]; // downcasting
Kedi a3 = (Kedi) o[1]; // downcasting
}
}
class Hayvan {
public static int x = 1;
}
class Kedi extends Hayvan {
public static int x = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment