Skip to content

Instantly share code, notes, and snippets.

@mrnirva
Created September 22, 2020 13:26
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/45e8a9cac167f517115f5ad7b38d94a9 to your computer and use it in GitHub Desktop.
Save mrnirva/45e8a9cac167f517115f5ad7b38d94a9 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();
/*
Hayvan sınıfını temel alarak
kedi ve kopek sınıflarından nesne oluşturduk
konustur metotlarını çağırarak bir nesnenin
birden fazla nesne gibi davranabildiğini gördük
*/
hayvan.konustur();
kedi.konustur();
kopek.konustur();
}
}
class Hayvan{
void konustur(){
System.out.println("Ses Yok");
}
}
class Kedi extends Hayvan{
@Override
void konustur() {
System.out.println("Miyav");
}
}
class Kopek extends Hayvan{
@Override
void konustur() {
System.out.println("Hav Hav");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment