Skip to content

Instantly share code, notes, and snippets.

@mrnirva
Last active September 22, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrnirva/d537ecf6c86cfaa6477b3b234f2a174b to your computer and use it in GitHub Desktop.
Save mrnirva/d537ecf6c86cfaa6477b3b234f2a174b to your computer and use it in GitHub Desktop.
package polymorphism;
public class CokBicimlilik {
public static void main(String[] args) {
Hayvan hayvan = new Hayvan();
Hayvan kedi = new Kedi();
Hayvan kopek = new Kopek();
if(kedi instanceof Hayvan){ // true döner
System.out.println("Kedi nesnesi Hayvan Sınıfından Türetilmiştir.");
}
if(kedi instanceof Kopek){ // false döner
System.out.println("Kedi nesnesi Kopek Sınıfından Türetilmiştir.");
}
if(kedi instanceof Kedi){ // ture döner
System.out.println("Kedi nesnesi Kedi Sınıfından Türetilmiştir.");
}
}
}
class Hayvan{
}
class Kedi extends Hayvan{
}
class Kopek extends Hayvan{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment