Created
October 12, 2017 17:55
-
-
Save Rahandi/bfb112501effa6079e7e8ae7fa31b6d3 to your computer and use it in GitHub Desktop.
Overriding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Binatang { | |
public void begerak(){ | |
System.out.println("Binatang bergerak sesuai kemampuannya"); | |
} | |
public void berkembangBiak(){ | |
System.out.println("Binatang berkembang biak sesuai kemampuannya"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mamalia extends Binatang { | |
//overriding method parent class | |
public void begerak(){ | |
System.out.println("Mamalia bergerak sebagian besar dengan kakinya"); | |
} | |
public void berlari(){ | |
System.out.println("Sebagian Mamalia dapat berlari"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PenggunaanOverriding { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Binatang b = new Binatang(); | |
Mamalia m = new Mamalia(); | |
Binatang bm = new Mamalia(); | |
b.begerak(); | |
m.begerak(); | |
bm.begerak(); | |
bm.berkembangBiak(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment